response.redirect (this page?)...short and sweet way to do this?

D

darrel

I have a 'cancel' button that should reload the current page. Ie, reset the
page back to it's initial state.

Is the best way to do this to simply have the event handler for that button
redirect the page to itself?

If so, is there a short-and-sweet way to write that out? Or do I need to
first grab the URL and parse it?

I don't want to hardcore the url as this might be used in different
locations.

-Darrel
 
S

Steve C. Orr [MVP, MCSD]

You should be able to use Response.Redirect(".") or
Response.Redirect(Request.URL)
 
D

darrel

Response.Redirect(Request.URL)

Oh. Duh. Missed the obvious on that one! ;o)

Thanks!

-Darrel
 
H

Hans Kesting

Dale said:
Why not just use an HTML Cancel button and save the round trip?

Dale

That might not work correctly: if postbacks have happened
(server side validators, autopostback, ...) then the values
of that latest postback will be restored, not the real initial values!

Hans Kesting
 
U

user

darrel said:
I have a 'cancel' button that should reload the current page. Ie, reset the
page back to it's initial state.

Is the best way to do this to simply have the event handler for that button
redirect the page to itself?

If so, is there a short-and-sweet way to write that out? Or do I need to
first grab the URL and parse it?

I don't want to hardcore the url as this might be used in different
locations.

-Darrel
Hello,

Hope this helps (see attached text file)

ChiefDnd

Private Sub btnCancel_Reset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel_Reset.Click
'/////////////////////////////////////////////////////////////////
' Clear the form (Textbox and DropDownList)
'/////////////////////////////////////////////////////////////////
Dim objC As Control
For Each objC In Page.Controls
Dim objType As Type = objC.GetType()
If objType.FullName = "System.Web.UI.HtmlControls.HtmlForm" Then
Dim objF As HtmlForm = CType(objC, HtmlForm)
Dim objWC As Control
For Each objWC In objF.Controls
Dim objWCType As Type = objWC.GetType()
If objWCType.FullName = "System.Web.UI.WebControls.TextBox" Then
Dim objTB As TextBox = CType(objWC, TextBox)
objTB.Text = ""
End If
If objWCType.FullName = "System.Web.UI.WebControls.DropDownList" Then
Dim objDDL As DropDownList = CType(objWC, DropDownList)
objDDL.SelectedIndex = 0
End If
Next objWC
End If
Next objC
lblMessage.Visible = False
'/////////////////////////////////////////////////////////////////
' Refill the form as needed
'/////////////////////////////////////////////////////////////////
SetupPage()
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top