I did this myself, where I had a page with two different registration formats for different types of users. What I did was split these two forms into my own ASP Panel and the panel setting DefaultButton, depending on what I wanted. Thus, when they finished typing in the form and pressed the enter key, he would send the correct button.
An example :
<asp:Panel id="panel1" DefaultButton="button1">
<asp:textbox id="textbox1"/>
<asp:textbox id="textbox2"/>
<asp:buton id="button1"/>
</asp:panel>
<asp:panel id="panel2" DefaultButton="button2">
<asp:textbox id="textbox3"/>
<asp:textbox id="textbox4"/>
<asp:button id="button2"/>
</asp:panel>
EDIT : Another method on how to do this by assigning the OnKeyPress property to your text fields. THIS IS A SEPARATE DECISION THAT I DESCRIBED IN TOP
An example :
function clickButton(e, buttonid){
var evt = e ? e : window.event;
var bt = document.getElementById(buttonid);
if (bt){
if (evt.keyCode == 13){
bt.click();
return false;
}
}
}
TextBox1.Attributes.Add("onkeypress",
"return clickButton(event,'" + Button1.ClientID + "')");
The following code is created in the code:
<input name="TextBox1" type="text" id="TextBox1" onkeypress="return
clickButton(event,'Button1')" />
source
share