Monday, November 01, 2010

How to implement a custom default button for a page

<%@ Page Language="C#" %>
<html>   
<head id="Head1" runat="server">
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script language="javascript">
        $(document).ready(function () {
            $(".TextBox").bind("keyup"function (evt) {
                evt = (evt) ? evt : window.event
                var charCode = (evt.which) ? evt.which : evt.keyCode
                if (charCode == 13)
                    __doPostBack('<%= btnDefault.UniqueID %>''');
                return true;
            });
            $(".TextBox").bind("keypress"function (evt) {
                evt = (evt) ? evt : window.event
                var charCode = (evt.which) ? evt.which : evt.keyCode
                if (charCode == 13)
                    return false;
                return true;
            });
        });
    </script>      
    <script runat="server">
        protected void Default(object sender, EventArgs e)
        {
            Response.Write(string.Format("Default button clicked at {0}",DateTime.Now.ToString("hh:mm:ss")));
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:TextBox runat="server" ID="TextBox1" CssClass="TextBox" onkeypress="return false" />
        <asp:TextBox runat="server" ID="TextBox2" CssClass="TextBox" onkeypress="return false" />
        <asp:TextBox runat="server" ID="TextBox3" CssClass="TextBox" onkeypress="return false" />
        <asp:TextBox runat="server" ID="TextBox4" CssClass="TextBox" onkeypress="return false" />
        <asp:TextBox runat="server" ID="TextBox5" CssClass="TextBox" onkeypress="return false" />        
        <hr />
        <asp:Button runat="server" ID="btnDefault" Text="Default" OnClick="Default" UseSubmitBehavior="false" />
        <asp:Button runat="server" ID="Button1" Text="Other" />
        <asp:Button runat="server" ID="Button2" Text="Other" />
        <asp:Button runat="server" ID="Button3" Text="Other" />
        <asp:Button runat="server" ID="Button4" Text="Other" />
        <asp:Button runat="server" ID="Button5" Text="Other" />
    </form>
</body>
</html>

No comments:

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...