Geeks With Blogs
Daily dotnet {notes on codes}

Here is a common method that you can use anywhere,

private void ResetFormControlValues(Control parent)
        {
            foreach (Control c in parent.Controls)
            {
                if (c.Controls.Count > 0)
                {
                    ResetFormControlValues(c);
                }
                else
                {
                    switch (c.GetType().ToString())
                    {
                        case "System.Web.UI.WebControls.TextBox":
                            ((TextBox)c).Text = "";
                            break;
                        case "System.Web.UI.WebControls.CheckBox":
                            ((CheckBox)c).Checked = false;
                            break;
                        case "System.Web.UI.WebControls.RadioButton":
                            ((RadioButton)c).Checked = false;
                            break;
                        case "System.Web.UI.WebControls.DropDownList":
                            ((DropDownList)c).SelectedIndex = -1;
                            break;

                    }
                }
            }
        }

Posted on Sunday, June 20, 2010 11:16 PM asp.net | Back to top


Comments on this post: Reset aspx form values

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Prasenjit | Powered by: GeeksWithBlogs.net