Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello,

i need to call javascript method on key press event of textbox at runtime in codebehind.

what is syntax to call method.

method of javascript is:

function numbersonly(e, decimal) {}

Thanks,
Posted
Updated 22-Nov-11 20:04pm
v2
Comments
Anuja Pawar Indore 23-Nov-11 5:12am    
server side use TextBox1_TextChanged() and write your logic in that

Their is nothing as "KeyPress" server side Event for Asp.Net TextBox. You may call your JavaScript function on OnTextChanged Event using ClientScript.RegisterStartupScript.
C#
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
   string eValue = "Something";
   decimal decimalValue = 100;
            
   ClientScript.RegisterStartupScript(this.GetType(), "MyScript",  "javascript:numbersonly(" + eValue + "," + decimalValue.ToString() + ")", true);

}


Have a look at below link for more information on OnTextChanged Event.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.textchanged.aspx
 
Share this answer
 
I guess this is how its done!

C#
<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="JavaScript method name()">
 
Share this answer
 
v3
Comments
jas.team 23-Nov-11 3:46am    
no it need to be called from code behind file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900