如何调用javascript方法 [英] How to call javascript method
本文介绍了如何调用javascript方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
我想从cs页面调用一个javascript方法,我在html select的onchange事件时调用它。当我在编辑案例中绑定控件时,我想通过调用javascript方法从cs页面填充该下拉列表。
提前感谢
Hello
I want to call a javascript method from cs page which I am calling at the time of onchange event of html select . when I bind controls in edit case I want to fill that dropdown from cs page by calling that javascript method .
thanks in advance
推荐答案
试试这个..
try this ..
<div id="divvvv" runat="server">
<select id="ddlSelect" onchange="changeTest()" name="select1">
<option value="0" selected="selected">Choose a color</option>
<option value="1">Red Star</option>
<option value="2">Yellow Star</option>
<option value="3">Pink Star</option>
</select>
in cs file call like this
divvvv.Attributes.Add("onClick", "javascript:return BindSelect();");
这是你如何从cs页面调用javascipt方法
this is how you can call javascipt method from cs page
StringBuilder strBuilder = new StringBuilder();
strBuilder.Append("<script laungauge='javascript'>");
strBuilder.Append(" MethodName();");
//javascript function name
strBuilder.Append("</script>");
//register script
Page.ClientScript.RegisterStartupScript(GetType(), "InitDiag", strBuilder.ToString());
将MethodName更改为你的javascript方法名称
change the MethodName to yours javascript methods name
尝试如下。
Hi,
try like below.
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), 'yourKey', 'YourJSFunction();', true);
参考 ClientScriptManager.RegisterClientScriptBlock方法(类型,字符串,字符串,布尔值) [ ^ ]
希望它有所帮助。
refer ClientScriptManager.RegisterClientScriptBlock Method (Type, String, String, Boolean)[^]
hope it helps.
这篇关于如何调用javascript方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文