Monday, October 18, 2010

Tie button to textbox control

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

No comments :

Post a Comment

AJAX, asp, Asp.net, asp.net and sql server security, Asp.net IntemIndex, C#, Css, DataBinder.Eval, DataKeyNames, Datalist, Datapager, DataSet, DataTable, DropDownList, FindControl, gridview, JavaScript, jquery, Listview, Paging, Regex, RegularExpression, Repeater, Server side validation, Sql Server, timer, timercallback, Validation, XML, xmlnode, XPath