单击用户控件按钮后如何从js文件调用javascript [英] how to call javascript from js file on click of user controls button
问题描述
我有一个包含xyz(a,b)javascript函数的abc.js文件,其中a,b来自我存储在用户控件的隐藏字段中的类库,并将其传递给xyz函数.我的问题是单击用户控件之类的按钮时传递给js函数的隐藏字段bt中的值,如
I have one abc.js file containing xyz(a,b) javascript function where a,b are coming from class library which I had stored in hidden fields of user control and passing it to xyz function.my problem is m getting value in hidden field bt while passing to js function on click of button of user control like,
btn.Attributes.Add("onClick", "javascript: xyz('"+ this.ClientID + "','" +HdnText.Text+ "');");
在dummy.aspx页上注册的用户控件.
??
registered user control on dummy.aspx page.
??
推荐答案
您好,
因此,请提供您的隐藏字段和ID,如下所示:
Hi there,
So give your hidden field and ID like so:
<input type="hidden" value="SomeValue" id="MyHiddenInputID" />
或在C#中执行:
or in C# do:
MyHiddenInput.ID = "MyHiddenInputID";
然后在javascriot中使用document对象访问其值:
Then in javascriot use the document object to access it''s value:
document.getElementById("MyHiddenInputID").value
您的完整按钮C#行将如下所示:
Your full button C# line would then look like:
btn.Attributes.Add("onclick", "javascript: xyz('" + this.ClientID + "', document.getElementById(\"MyHiddenInputID\").value);");
请记住,使用HtmlButton(来自HTML控件)而不是按钮(来自WebControls)-后者不会为您提供html input [type = button]但会给您html input [type = submit]-这不是您想要的.
希望这会有所帮助,
Ed
Remember to use HtmlButton (from HTML Controls) not a Button (from WebControls) - the latter will not give you an html input[type=button] but and html input[type=submit] - which isn''t what you want.
Hope this helps,
Ed
btn.Attributes.Add("onclick", "javascript: xyz('" + this.ClientID + "',document.getElementById('"+this.ClientID+"_HdnText').value);")
这篇关于单击用户控件按钮后如何从js文件调用javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!