Click here to Skip to main content
12,691,453 members (29,149 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# Javascript
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 22-Nov-11 21:02pm
Updated 22-Nov-11 21:04pm
v2
Comments
Anuja Pawar Indore 23-Nov-11 5:12am
   
server side use TextBox1_TextChanged() and write your logic in that
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Their is nothing as "KeyPress" server side Event for Asp.Net TextBox. You may call your JavaScript function on OnTextChanged Event using ClientScript.RegisterStartupScript.
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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

I guess this is how its done!

<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="JavaScript method name()">
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.170117.1 | Last Updated 23 Nov 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100