Asp.Net Clear all controls value reset

Asp.Net Clear all controls value reset

Today, We want to share with you Asp.Net Clear all controls value reset.
In this post we will show you Find Page control and clear its value in Asp.Net, hear for Get Master Page Control Value In Content Page and c# – Clear all controls in a ASP.NET page we will give you demo and example for implement.
In this post, we will learn about reset or clear all asp.net controls/fields on web page/form ? with an example.

Introduction

In this post I will demonstrate how you can find page control and clear control value.
Below I have provided Asp.net markup for several mostly used control. On button click event handler i have wriiten code to clear the value of control.

Example for clear control value

Asp.net markup

Reset CheckBox
Reset CheckBoxList Red Pink White Green
Clear TextBox
Reset DropDownList -- Select -- Red Pink White Black
Reset RadioButton
Reset RadioButtonList Apple Orange Banana Mango
Reset Label Text  &nbsp

C#.net code to clear control value

 protected void btnReset_Click(object sender, EventArgs e)
        {
            foreach (Control _Control in frmMain.Controls)
            {
                //Clear the TextBox content
                if (_Control is TextBox)
                {
                    ((TextBox)(_Control)).Text = string.Empty;
                }
                //Clear the Label text
                else if (_Control is Label)
                {
                    ((Label)(_Control)).Text = string.Empty;
                }
                // Select default item
                else if (_Control is DropDownList)
                {
                    ((DropDownList)(_Control)).ClearSelection();
                }
                //uncheck the selection
                else if (_Control is CheckBox) 
                {
                    ((CheckBox)(_Control)).Checked = false;
                }
                // uncheck all the selection
                else if (_Control is CheckBoxList) 
                {
                    ((CheckBoxList)(_Control)).ClearSelection();
                }
                //uncheck the selection
                else if (_Control is RadioButton) 
                {
                    ((RadioButton)(_Control)).Checked = false;
                }
                // uncheck all the selection
                else if (_Control is RadioButtonList) // or else if (_Control.GetType().Equals(typeof(RadioButtonList)))
                {
                    ((RadioButtonList)(_Control)).ClearSelection();
                }
                //clear the value of HiddenField control
                else if (_Control is HiddenField)
                {
                    ((HiddenField)(_Control)).Value = string.Empty;
                }
            }
        }

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Get Master Page Control Value In Content Page.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment