运行时按键事件的javascript调用方法 [英] call method of javascript on key press event on runtime

查看:76
本文介绍了运行时按键事件的javascript调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我需要在代码隐藏时在运行时在文本框的按键事件上调用javascript方法.

调用方法的语法是什么.

javascript的方法是:

仅函数编号(e,十进制){}

谢谢,

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,

推荐答案

它们与Asp.Net TextBox的服务器端事件"b> KeyPress "完全不同.您可以使用ClientScript.RegisterStartupScriptOnTextChanged事件上调用JavaScript函数.
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);

}



请查看下面的链接,以获取有关OnTextChanged事件的更多信息.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.textchanged.aspx



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


我想这是怎么做的!

I guess this is how its done!

<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="JavaScript method name()">


这篇关于运行时按键事件的javascript调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆