Thursday, July 7, 2011

Setting Default Button for textbox in asp.net 1.1

Hi,
Today I am posting a small tip for Setting default button for a text box when press Enter in asp.net 1.1.
The method below describes the way to specify a default button to submit when the user hits the enter key in a textbox.
1.Add the below Script.

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;
}
}
}

2.In Code behind Write the following...

TextBox1.Attributes.Add("OnKeyPress", "return clickButton(event,'" + Button1.ClientID + "')");

For Complete details plz refer here

No comments:

Post a Comment