TextBox Submit Form On Enter Key press Using DefaultButton In Asp.Net 2.0,3.5,4.0, We can set Defaultbutton property either in Form or in panel Whenever we want user to submit a form by pressing enter key after filing out some textboxes on the aspx page, though we provide the button to submit the form but user prefer to press enter and expect the form to be submitted
But in ASP.NET when user press enter key the page gets post back but the button event doesn't get fired hence whatever code u've written in the click event doesn't get executed and it just like refreshing the page , to handle this situation in ASP.NET 2.0 ,we need to set the Defaultbutton property which indicates which button events should get fired when user press enter key to submit the form.
<form id="form1" runat="server" defaultbutton="Button1">
<div>
<asp:TextBox ID="TextBox1" runat="server"/>
<asp:TextBox ID="txtTest" runat="server"/>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit"/>
</div>
</form>
or if we use panel than
<asp:Panel ID="Panel1" runat="server" defaultbutton="Button1">
ASP.NET TextBox Submit Form On Enter Key DefaultButton
Posted by
Unknown
If you like this post than join us or share
Subscribe to:
Post Comments (Atom)
8 comments:
When I try to enclose my page in asp:panel tags, my aspx.vb page can't find the controls (lblSomething.text = "abc") doesn't work anymore
http://twitter.com/dotnetfreak
This comment has been removed by a blog administrator.
This comment has been removed by a blog administrator.
This comment has been removed by a blog administrator.
This comment has been removed by a blog administrator.
This comment has been removed by a blog administrator.
This comment has been removed by a blog administrator.
Post a Comment