Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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:
JavaScript
document.getElementById(<%="UserControl_txtBox1.ClientID%>").value = "";


Please help.

Thanks in advance.
Posted

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
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900