I have content page with master page. On the content page I want to clear all text in all textboxes, uncheck any checked checkboxes and set all dropdownlist to index of 0. I created the below method to accomplish this and it works great. I have other pages that will need to use this same functionality. My question is it possible to place this method is a class, create an instance of the class and call the method on other pages. I tried placing in a class in it complains about the word master by underlining it in red - The name "Master" doesn't exit in current context. I have been searching online and haven't found any examples of someone doing this so wondering if it is possible.
private void ClearForm(string ContentPlaceHolder)
{
ContentPlaceHolder cph = (ContentPlaceHolder)Master.FindControl(ContentPlaceHolder);
foreach (Control c in cph.Controls)
{
if (c.GetType() == typeof(TextBox))
{
((TextBox)c).Text = "";
}
if (c.GetType() == typeof(CheckBox))
{
((CheckBox)c).Checked = false;
}
if (c.GetType() == typeof(DropDownList))
{
((DropDownList)c).SelectedIndex = 0;
}
}
}//end ClearForm