Friday, April 3, 2009

how to set default button dynamically in page.

There are many way to sortout this problem.
like wrapup each seprate panel and set the defaultbutton property on panel.or set the WebForm_FireDefaultButton onclick event of text box.But i like mostand prefer to keep this in practice is call javaScript function of for setdefault button this is aplicabe on firefox,IE,Safari id did not tyr it for netscape but i belive it will run. this function is
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;
}
}
}
we can implement it as follws
TextBox1.Attributes.Add("onkeypress", "return clickButton(event,'" + Button2.ClientID + "')"); TextBox2.Attributes.Add("onkeypress", "return clickButton(event,'" + Button3.ClientID + "')"); TextBox3.Attributes.Add("onkeypress", "return clickButton(event,'" + Button4.ClientID + "')"); TextBox4.Attributes.Add("onkeypress", "return clickButton(event,'" + Button5.ClientID + "')");

Thanks
HelponDesk Team

No comments: