Programming Journal C#, Java, SQL and to a lesser extent HTML, CSS, XML, and regex. I made this so other programmers could benefit from my experience.

Monday, February 18, 2008

Drilling down a nested master page in ASP.NET to reset a form

Here is an example of drilling down a master page in ASP.NET to reset a form's TextBox controls:

protected void btnqReset_Click(object sender, EventArgs e)
{

try
{
ContentPlaceHolder childMasterContent = (ContentPlaceHolder)Page.Form.FindControl("ParentMasterContent").FindControl("ChildMasterContent");
Control ctrlForm = childMasterContent.FindControl("upnlQueryMoreCriteria").FindControl("pnlQueryMoreCriteria");
Control[] queryControls = { ctrlForm };
for (int i = 0; i < 1; i++)
{
if (queryControls[i].Controls != null)
{
foreach (Control ct in queryControls[i].Controls)
{
if (ct.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox"))
{
((TextBox)ct).Text = "";
}
}
}
}
}
catch (Exception ex)
{
log.Error("Unable to reset query criteria: " + ex.Message + ex.StackTrace);

}
}

No comments: