Click here to Skip to main content
15,878,871 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I have a drop down list and few panels having textboxes in my design. In the dropdown list, I have embedded few branch names. My procedure is I'll select any branch and write some information in textboxes, then save it.
Its working fine.

Suppose when I select branch1, and write some information in textboxes, in the middle of the process, I will change branch1 to branch2, then when I select different branch in the midst of the process, I need to clear all the controls in my design page. How can I do it? Please do help.

Thank You
Posted
Updated 13-May-16 22:15pm
Comments
Sumit_Kumar_Sinha 18-Jan-13 1:16am    
You use dropdownlist OnIndexChanging then clear controls values...
Bhargav.456 18-Jan-13 1:32am    
Thanks, Suppose if I have 40 textboxes, how can I do?

1.add event as Dropdown_SelectedIndexChanged
2.then
C#
textbox.text=String.Empty;

like example

C#
protected void DropDownProducts_SelectedIndexChanged(object sender, EventArgs e)
        {
textbox.text=String.Empty;
}
 
Share this answer
 
Comments
Bhargav.456 18-Jan-13 1:32am    
Thanks, Suppose if I have 40 textboxes, how can I do?
AdityaPratapSingh 18-Jan-13 1:52am    
then you should use this code
protected void DropDownProducts_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (var item in form1.Controls)
{
if (item is TextBox)
{
((TextBox)item).Text = "";
}
}
}
Use javascript to clear all fields when value in dropdownlist changed.

JavaScript
<script type="text/javascript">
       function onValueChange()
       {
           try {
               document.getElementById('<%=TextBox_Name.ClientID%>').value="";

           }
           catch(e){alert(e.message);}
       }
   </script>


Call this function on
HTML
onchange='onValueChange();'
event of dropdownlist.

Must add
HTML
ClientIDMode="Static"
attribute to textbox which you want to make clear.
 
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