Saturday, December 29, 2018

Confirmation Box In Button Click

Confirmation Box In Button Click

protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["S_userlogId"] != null && Session.Count > 0)
        {
              if (!IsPostBack)
                {
                    init();

                }
        }
        else
        {
            Response.Redirect("~/Default.aspx");
        }
        btn_SaveAsDraft.Attributes.Add("onclick", "javascript:return confirm('Confirm to save the information and proceed to fill up data at other sections?')");
    }

HTML

<asp:Button ID="btn_SaveAsDraft" runat="server"
                            onclick="btn_SaveAsDraft_Click" Text="Save &amp; Next"
                            CssClass="ButtonText" />

Tuesday, December 25, 2018

e.KeyCode == Keys.Enter


if (e.KeyCode == Keys.Enter)
  {
 MessageBox.Show("Enter Key Pressed ");
  }
 
 
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                MessageBox.Show("Enter key pressed");
            }
        }
    }
}
 

Sunday, December 16, 2018

CheckIfNumeric

namespace ConsoleApplication10
{
    class Program
    {
        static void Main(string[] args)
        {
            CheckIfNumeric("A");
            CheckIfNumeric("22");
            CheckIfNumeric("Potato");
            CheckIfNumeric("Q");
            CheckIfNumeric("A&^*^");

            Console.ReadLine();
        }

        private static void CheckIfNumeric(string input)
        {
            if (input.IsNumeric())
            {
                Console.WriteLine(input + " is numeric.");
            }
            else
            {
                Console.WriteLine(input + " is NOT numeric.");
            }
        }
    }

    public static class StringExtensions
    {
        public static bool IsNumeric(this string input)
        {
            return Regex.IsMatch(input, @"^\d+$");
        }
    }
}