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+$");
        }
    }
}

Monday, October 15, 2018

SQL date format query

DATE ONLY FORMATS
Format # Query Sample
1 select convert(varchar, getdate(), 1) 12/30/06
2 select convert(varchar, getdate(), 2) 06.12.30
3 select convert(varchar, getdate(), 3) 30/12/06
4 select convert(varchar, getdate(), 4) 30.12.06
5 select convert(varchar, getdate(), 5) 30-12-06
6 select convert(varchar, getdate(), 6) 30 Dec 06
7 select convert(varchar, getdate(), 7) Dec 30, 06
10 select convert(varchar, getdate(), 10) 12-30-06
11 select convert(varchar, getdate(), 11) 06/12/30
12 select convert(varchar, getdate(), 12) 061230
23 select convert(varchar, getdate(), 23) 2006-12-30
101 select convert(varchar, getdate(), 101) 12/30/2006
102 select convert(varchar, getdate(), 102) 2006.12.30
103 select convert(varchar, getdate(), 103) 30/12/2006
104 select convert(varchar, getdate(), 104) 30.12.2006
105 select convert(varchar, getdate(), 105) 30-12-2006
106 select convert(varchar, getdate(), 106) 30 Dec 2006
107 select convert(varchar, getdate(), 107) Dec 30, 2006
110 select convert(varchar, getdate(), 110) 12-30-2006
111 select convert(varchar, getdate(), 111) 2006/12/30
112 select convert(varchar, getdate(), 112) 20061230



TIME ONLY FORMATS
8 select convert(varchar, getdate(), 8) 00:38:54
14 select convert(varchar, getdate(), 14) 00:38:54:840
24 select convert(varchar, getdate(), 24) 00:38:54
108 select convert(varchar, getdate(), 108) 00:38:54
114 select convert(varchar, getdate(), 114) 00:38:54:840



DATE & TIME FORMATS
0 select convert(varchar, getdate(), 0) Dec 12 2006 12:38AM
9 select convert(varchar, getdate(), 9) Dec 30 2006 12:38:54:840AM
13 select convert(varchar, getdate(), 13) 30 Dec 2006 00:38:54:840AM
20 select convert(varchar, getdate(), 20) 2006-12-30 00:38:54
21 select convert(varchar, getdate(), 21) 2006-12-30 00:38:54.840
22 select convert(varchar, getdate(), 22) 12/30/06 12:38:54 AM
25 select convert(varchar, getdate(), 25) 2006-12-30 00:38:54.840
100 select convert(varchar, getdate(), 100) Dec 30 2006 12:38AM
109 select convert(varchar, getdate(), 109) Dec 30 2006 12:38:54:840AM
113 select convert(varchar, getdate(), 113) 30 Dec 2006 00:38:54:840
120 select convert(varchar, getdate(), 120) 2006-12-30 00:38:54
121 select convert(varchar, getdate(), 121) 2006-12-30 00:38:54.840
126 select convert(varchar, getdate(), 126) 2006-12-30T00:38:54.840
127 select convert(varchar, getdate(), 127) 2006-12-30T00:38:54.840

Wednesday, September 26, 2018

Concat in SQL Query

Concat in SQL Query

SELECT (au_lname + ', ' + au_fname) AS Name
FROM authors
ORDER BY au_lname ASC, au_fname ASC
Here is the result set:
Name                                                           
-------------------------------------------------------------- 
Bennet, Abraham                                                
Blotchet-Halls, Reginald                                       
Carson, Cheryl                                                 
DeFrance, Michel                                               
del Castillo, Innes      

Script to Count text length in textbox


<script type="text/javascript">
    function ismaxlength(objTxtCtrl, nLength) {
        if (objTxtCtrl.getAttribute && objTxtCtrl.value.length > nLength)
            objTxtCtrl.value = objTxtCtrl.value.substring(0, nLength)

        if (document.all)
            document.getElementById('<%= lblCaption.ClientID %>').innerText = objTxtCtrl.value.length + ' daripada ' + nLength;
        else
            document.getElementById('<%= lblCaption.ClientID %>').textContent = objTxtCtrl.value.length + ' daripada ' + nLength;

    }
</script>


<asp:TextBox ID="txtNote" runat="server" Width="381px" Rows="3" onkeyup="return ismaxlength(this,250)"
                    TextMode="MultiLine"  ></asp:TextBox> <br />
<asp:Label runat="server" ID="lblCaption" Font-Bold="True" Visible="True">

Set Back Button


//back button
Button5.Attributes.Add("onClick", "javascript:history.back(); return false;");

//confirmation button
btnRemoveGroup.Attributes.Add("onclick", "javascript:return confirm('Pastikah anda ingin hapuskan maklumat tersebut ?')");


 //Hyperlink
  <asp:TemplateField HeaderText="Nama">
                  <ItemTemplate>
                   <asp:HyperLink HeaderText="Nama"  Target="_top" ID="HyperLink1" runat="server" Text='<%# Eval("Nama_Ahli") %>' NavigateUrl='<%# Eval("No_Ahli", "~/Report/MemberDetail.aspx?prm_ID={0}") %>'></asp:HyperLink>
                  </ItemTemplate>
                     <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                     <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" />
                </asp:TemplateField>