Thursday 8 August 2019

Clear all forms controls from code-behind asp.net c#

/////////////

Use NameSpace

1. using System.Web.UI;
2. using System.Web.UI.HtmlControls;


public static void Clear_Controls_Comman(Panel ControlIDs)
    {
        foreach (Control item in ControlIDs.Controls)
        {
            if (item is TextBox)
            {
                TextBox t = item as TextBox;
                t.Text = "";
            }
            else if (item is CheckBox)
            {
                CheckBox t = item as CheckBox;
                t.Checked = false;
            }
            else if (item is DropDownList)
            {
                DropDownList t = item as DropDownList;
                t.ClearSelection();
                if (t.Items.Count > 0)
                {
                    t.SelectedIndex = 0;
                }
            }
            else if (item is CheckBoxList)
            {
                CheckBoxList t = item as CheckBoxList;
                t.ClearSelection();
            }
            else if (item is RadioButton)
            {
                RadioButton t = item as RadioButton;
                t.Checked = false;
            }
            else if (item is RadioButtonList)
            {
                RadioButtonList t = item as RadioButtonList;
                t.ClearSelection();
            }
            else if (item is HtmlInputText)
            {
                HtmlInputText t = item as HtmlInputText;
                t.Value = "";
            }
            else if (item is HtmlTextArea)
            {
                HtmlTextArea t = item as HtmlTextArea;
                t.InnerText = "";
            }
            else if (item is HtmlInputCheckBox)
            {
                HtmlInputCheckBox t = item as HtmlInputCheckBox;
                t.Checked = false;
            }

        }
    }

No comments:

Post a Comment

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...