Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clear controls of a page

Status
Not open for further replies.

lunargirrl

Programmer
Jan 26, 2004
77
BR
How can I clear the controls of a page (labels, textboxes, etc..) when the back and forward buttons of the browser are pressed??

Thanks a lot,
Gis.
 
This should work, assuming that you're trying to clear the control's contents (you might have to change it up a bit - it's hand-coded):

Code:
foreach(System.Web.UI.Control c in this.Page.Controls)
{
    if(c.GetType() == typeof(Label))
	((Label)c).Text	= String.Empty;
    if(c.GetType() == typeof(TextBox))
	((TextBox)c).Text = String.Empty;
    if(c.GetType() == typeof(DropDownList))
	((DropDownList)c).Items.Clear();
}

You'll also have to add in handlers for any other control types that you want to clear on your page.

Hope that helps

-----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy
 
AtomicChip, do i place that in the page load??

thanks
gis.
 
You'd probably want to place that on your back and forward button click events.

-----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy
 
how can i manipulate the back and forward buttons of my browser by code? in vs.net?

Thanks :))
Gis.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top