Applying Enter as default key for the textbox

In this tutorial i will show you how to apply some button as default key for the textbox on clicking the enter.

Take one textbox & take one button & go to the source of the code....

It will look something like this....

<asp:TextBox ID="TextBox2" runat="server">asp:TextBox>
<asp:Button ID="Button1"runat="server" Text="Button" />

Now to make Button1 as default key for textbox on enter we ndde to add both textbox & button in the
panel like this...

<asp:Panel ID="Panel1" runat="server">
<asp:TextBox ID="TextBox2" runat="server">asp:TextBox>
<
asp:Button ID="Button1"runat="server" Text="Button" />
&lt/asp:Panel>

Now we have to add one property to panel which is DefaultButton="Button1"

After adding this your code will look something like this...

<asp:Panel ID="Panel1" runat="server" DefaultButton="Button1">
<
asp:TextBox ID="TextBox2" runat="server">asp:TextBox>
<
asp:Button ID="Button1"runat="server" Text="Button" />
&lt/asp
:Panel>


this make Button1 as default key for the panel & on clicking "Enter" event of
button will be raised.

0 comments:

Post a Comment