Find all ASP.NET loop through controls on Form Clear of specific type
In this Post We Will Explain About is Find all ASP.NET loop through controls on Form Clear of specific type With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to HOW TO FIND ALL ASP.NET CONTROLS OF SPECIFIC TYPE Example
In this post we will show you Best way to implement Finding all controls in an ASP.NET Panel, hear for Finding all controls of a specific type on a page using ASP.NET with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.
how can you loop through all controls on an asp.net web form
While going on livepage it can be list the tag required to perform some an action based perform on the type of the form control. Finding list form input controls now on the some livepage and then clearing list the form elements as well as some data resetting means defult settings their values was required in HTML Form my some case. Here We have provided an some example how We achieved that.
here Make a simple livepage and place HTML Elements Like as a checkbox, checkboxlist, HTML textbox, HTML form elements dropdownlist, form elements radiobutton, form elements radiobuttonlist, form elements label as well as some input hiddenfield controls etc.
HTML Source
Asp.Net C# source Code
to find html some controls by their more type and clear values
protected void data_clear_reset(object sender, EventArgs e) { foreach (Control liveCtrl in live_form.Controls) { if (liveCtrl is TextBox)// or if (liveCtrl.GetType().Equals(typeof(TextBox))) { ((TextBox)(liveCtrl)).Text = string.Empty; } else if (liveCtrl is Label) // or else if (liveCtrl.GetType().Equals(typeof(Label))) { ((Label)(liveCtrl)).Text = string.Empty; } else if (liveCtrl is DropDownList)// or else if (liveCtrl.GetType().Equals(typeof(DropDownList))) { ((DropDownList)(liveCtrl)).ClearSelection(); } else if (liveCtrl is CheckBox) // or else if (liveCtrl.GetType().Equals(typeof(CheckBox))) { ((CheckBox)(liveCtrl)).Checked = false; } else if (liveCtrl is CheckBoxList) // or else if (liveCtrl.GetType().Equals(typeof(CheckBoxList))) { ((CheckBoxList)(liveCtrl)).ClearSelection(); } else if (liveCtrl is RadioButton) // or else if (liveCtrl.GetType().Equals(typeof(RadioButton))) { ((RadioButton)(liveCtrl)).Checked = false; } else if (liveCtrl is RadioButtonList) // or else if (liveCtrl.GetType().Equals(typeof(RadioButtonList))) { ((RadioButtonList)(liveCtrl)).ClearSelection(); } else if (liveCtrl is HiddenField) //or else if (liveCtrl.GetType().Equals(typeof(HiddenField))) { ((HiddenField)(liveCtrl)).Value = string.Empty; } } }
Asp.Net VB Source Code
to list the find some controls by their list the type and clear values
Protected Sub data_clear_reset(sender As Object, e As EventArgs) Handles btnReset.Click 'Loop through list the control present on the web livepage/form For Each liveCtrl As Control In live_form.Controls 'value check condition for list TextBox controls on the livepage and clear them If TypeOf liveCtrl Is TextBox Then DirectCast(liveCtrl, TextBox).Text = String.Empty 'value check condition for list Label controls on the livepage and clear them ElseIf TypeOf liveCtrl Is Label Then DirectCast(liveCtrl, Label).Text = String.Empty 'value check condition for list DropDownList controls on the livepage and reset them ElseIf TypeOf liveCtrl Is DropDownList Then DirectCast(liveCtrl, DropDownList).ClearSelection() 'value check condition for list CheckBox controls on the livepage and unchecked the selection ElseIf TypeOf liveCtrl Is CheckBox Then DirectCast(liveCtrl, CheckBox).Checked = False 'value check condition for list CheckBoxList controls on the livepage and unchecked list the selections ElseIf TypeOf liveCtrl Is CheckBoxList Then DirectCast(liveCtrl, CheckBoxList).ClearSelection() 'value check condition for list RadioButton controls on the livepage and unchecked the selection ElseIf TypeOf liveCtrl Is RadioButton Then DirectCast(liveCtrl, RadioButton).Checked = False 'value check condition for list RadioButtonList controls on the livepage and unchecked the selection ElseIf TypeOf liveCtrl Is RadioButtonList Then DirectCast(liveCtrl, RadioButtonList).ClearSelection() 'value check condition for list hiddenfield controls on the livepage and clear them ElseIf TypeOf liveCtrl Is HiddenField Then DirectCast(liveCtrl, HiddenField).Value = String.Empty End If Next End Sub
You are Most welcome in my youtube Channel Please shubscibe my channel. and give me feedBackMore Details……
Angularjs Example
I hope you have Got What is HOW TO FIND ALL ASP.NET CONTROLS OF SPECIFIC TYPE AND CLEAR THEIR VALUES And how it works.I would Like to have FeaeBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.