如何从ascx页面的aspx中调用js函数 [英] How to call a js function in aspx from ascx page
本文介绍了如何从ascx页面的aspx中调用js函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面的代码中,我在sample.ascx中有一个文本框,在.aspx中有一个javascript函数,如何从ascx页面调用js函数.
Do.aspx
Js:
In the below code i have textbox in sample.ascx and a javascript function in .aspx how can i call js function from ascx page.
Do.aspx
Js:
function But2() {
document.getElementById("hidRectX").value = "431";
document.getElementById("hidRectY").value = "312";
document.getElementById("hidRectX1").value = "175";
document.getElementById("hidRectY1").value = "40";
DisplayRect();
moveScroll();
}
sample.ascx
< asp:TextBox ID ="txtField" runat ="server" width ="200Px">/xml>
sample.ascx
<asp:TextBox ID="txtField" runat="server" width="200Px">/xml>
推荐答案
您好,
您可以尝试使用此代码,它可能会起作用
Hello,
You can try out this code it might work
string strScript = "txtField";
if (!Page.ClientScript.IsStartupScriptRegistered("myscript"))
Page.ClientScript.RegisterStartupScript(this.But2(), "myscript", strScript, true);
这篇关于如何从ascx页面的aspx中调用js函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文