How to clear multiple controls? [Resolved]

Posted by Susanthampy under C# on 7/29/2011 | Points: 10 | Views : 5882 | Status : [Member] [MVP] | Replies : 6
How to clear multiple controls (textbox, dropdownlist) in a single button click using c#?

Regards,
Susan



Responses

Posted by: SheoNarayan on: 7/29/2011 [Administrator] HonoraryPlatinum | Points: 50

Up
0
Down

Resolved
Hi Susan,

Here is the code to rest the values of the TextBoxes http://www.dotnetfunda.com/codes/code9-how-to-empty-all-textboxes-of-the-page-at-one-shot-.aspx

If you can enhance this code by changing this like if (c is TextBox) for the dropdown or other controls this would become what you are looking for.

In case you are looking for using the JavaScript, read this http://www.dotnetfunda.com/codes/code599-reset-all-form-elements-to-their-default-values-in-javascript-.aspx.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Susanthampy, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lalji_mer on: 7/29/2011 [Member] Bronze | Points: 25

Up
0
Down
you will get guide from this link hope this link will help you....

http://forums.asp.net/t/1622631.aspx/1?Reset+the+value+of+control+on+cancle+button+click+using+jqurey

LP MER

Susanthampy, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A4u_6178 on: 7/29/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,
To clear textbox use
TextBox1.Text = string.Empty;

To clear radio button checkboxes..
CheckBox2.Checked = false;

RadioButton1.Checked = false;

For dropdownlist use like this..
<asp:DropDownList ID="DropDownList2" AutoPostBack="true" runat="server" 

onselectedindexchanged="DropDownList2_SelectedIndexChanged">
<asp:ListItem Value="0" >--select--</asp:ListItem>
<asp:ListItem Value="1" >item1</asp:ListItem>
<asp:ListItem Value="2" >item2</asp:ListItem>
<asp:ListItem Value="3" >item3</asp:ListItem>
</asp:DropDownList>

to clear selection..
DropDownList2.SelectedValue = "0";


Thanks & Regards,

Susanthampy, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hemanthlaxmi on: 7/29/2011 [Member] Starter | Points: 25

Up
0
Down
Hi please try to use this for clearing Text boxes.
 void GetAllTextBox(Control ctrl)

{
if (ctrl != null)
{
foreach (Control c in ctrl.Controls)
{
if (c is TextBox)
{
((TextBox)c).Text = String.Empty;
}
}
}

}


If this helps you .
Please "Mark as Answer"

Susanthampy, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Susanthampy on: 8/2/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Thank u friends..............

Regards,
Susan

Susanthampy, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 8/2/2011 [Member] Bronze | Points: 25

Up
0
Down
Write down code like:

foreach(Control ct in Page.Controls)
{
if (ct is typeof(TextBox))
((TextBox)ct).Text = string.Empty;
else{
if(ct is typeof(DropDownList))
((DropDownList)ct).ClearSelection();
}
}


this way u can write statement for each control which are there on ur page.

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Susanthampy, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response