How To Add Default Button(For IE and Mozila)

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DefaultButton.aspx.cs"
 Inherits="DefaultButton" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
   <title>Untitled Page</title>
   <script type="text/javascript">
       function press(evt)
       {
           if(evt.which || evt.keyCode)
           {
               if ((evt.which == 13) || (evt.keyCode == 13))
               {
                
                   var buttonid = '<%=Button11.ClientID %>';
                   __doPostBack(buttonid,'');
                   return false;
               }
           }
           else
           {
               return true;
           }
       }
   </script>
</head>
<body>
   <form id="form1" runat="server">
   <div>
       <asp:TextBox ID="TextBox11" runat="server"
onkeypress="press(event);"></asp:TextBox>
       <asp:Button ID="Button11" runat="server" Text="Button"
OnClick="Button11_Click" />
   </div>
   </form>
</body>
</html>



using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class DefaultButton : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)
   {
       ClientScript.GetPostBackEventReference(this, string.Empty);
   }

   protected void Button11_Click(object sender, EventArgs e)
   {
       Response.Write("button clicked");
   }
}

No comments:

Post a Comment