本文是小编为大家收集整理的关于使用Javascript重置ASPX中的ASCX的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。
问题描述
你好,
我有一个 ascx 控件,它有 4 个文本框、2 个下拉菜单、2 个复选框和 2 个单选按钮.我已将此控件添加到我的 aspx 页面.
我的 ASPX 页面有两个按钮保存和重置.
我想使用javascript重置aspx页面中ascx的所有控件.但我收到一条错误消息,指出无法找到控件.
我使用的javascript如下:
document.getElementById(<%="UserControl_txtBox1.ClientID%>").value = "";
请帮忙.
在此先感谢.
推荐答案
您好,
如果您没有限制使用 javascript 来重置 UserControl 中的控件,那么您可以使用委托来调用 UserControl 中的 Reset 方法.
希望您对委托[^]
谢谢
-Amit Gajjar
嗨,
据我了解,在你的javascript中,首先在你的页面中找到Usercontrol实例,然后在你的usercontrol中找到文本框.
这就是我在我的 aspx.cs 中所做的.在 javascript 中也应该是一样的.
我在我的 aspx 页面的选项卡面板中有一个用户控件.UserControl ucname = new UserControl(); ucname = tabPnlUser.FindControl("User") as UserControl; TextBox txtucFirstName = (TextBox)ucname.FindControl("txtFirstName"); txtucFirstName.Text = "";
希望这会有所帮助.
问题描述
Hi,
I have a ascx control having 4 textboxes, 2 dropdowns, 2 check boxes and 2 radio buttons. I have added this control to my aspx page.
My ASPX page has two buttons Save and Reset.
I want to reset all the controls of ascx in aspx page using javascript. But I get an error stating unable to find the control.
The javascript used by me as follows:
document.getElementById(<%="UserControl_txtBox1.ClientID%>").value = "";
Please help.
Thanks in advance.
推荐答案
Hi,
If you do not have constraint to use javascript to reset your controls in UserControl then you can use delegate to call the Reset method in the UserControl.
Hope you have idea about Delegate[^]
Thanks
-Amit Gajjar
Hi,
As per my understanding , in your javascript first find the Usercontrol instance in your page and then find the text box in your usercontrol.
This is how i did in my aspx.cs.Should be the same in javascript as well.
i have a usercontrol in a tab panel in my aspx page.
UserControl ucname = new UserControl(); ucname = tabPnlUser.FindControl("User") as UserControl; TextBox txtucFirstName = (TextBox)ucname.FindControl("txtFirstName"); txtucFirstName.Text = "";
Hope this helps.