public static void TieButton(Page page,Control TextBoxToTie,Control ButtonToTie ) { string JsScript = ""; if (ButtonToTie is LinkButton) { JsScript = "if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {"+ page.ClientScript.GetPostBackEventReference( ButtonToTie, "" ).Replace( ":", "$" ) + "; return false;} else return true;"; } else if (ButtonToTie is ImageButton) { JsScript = "if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {"+ page.ClientScript.GetPostBackEventReference( ButtonToTie, "" ).Replace( ":", "$" ) + ";return false;} else return true;"; } else { JsScript = "if ((event.which && event.which == 13) || "+ "(event.keyCode && event.keyCode == 13)) {document."+ "forms[0].elements['"+ ButtonToTie.UniqueID.Replace( ":", "_" ) + "'].click();return false; } else return true; "; } if (TextBoxToTie is HtmlControl) { ((HtmlControl) TextBoxToTie).Attributes.Add( "onkeydown", JsScript ); } else if (TextBoxToTie is WebControl) { ((WebControl) TextBoxToTie).Attributes.Add( "onkeydown", JsScript ); } }
Monday, October 18, 2010
Tie button to textbox control
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment