Avatar of jn1480
jn1480Flag for United States of America

asked on 

Response.Redirect History -1?

I am handling a FormView's Cancel button as follows in the code.

What I would rather do is simply tell it to go back just one page in the browser's history.
Or perhaps if this is not available, could I pass it the ID of the record I am currently working with in the formView?

Any thoughts? Thanks!
Protected Sub fvContent_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewCommandEventArgs) Handles fvContent.ItemCommand
        If e.CommandName = "Cancel" Then
            Response.Redirect("Pages.aspx")
        End If
    End Sub

Open in new window

ASP.NET

Avatar of undefined
Last Comment
jn1480
Avatar of daveamour
daveamour
Flag of United Kingdom of Great Britain and Northern Ireland image

You can write code to render cleint side javascript:

window.history.go(-1);
Avatar of jn1480
jn1480
Flag of United States of America image

ASKER

Yeah - I was kind of hoping for something like that - but I don't know how to write/call JS in ASP.net - very much a newbie... any chance you could show me?
Avatar of daveamour
daveamour
Flag of United Kingdom of Great Britain and Northern Ireland image

Well depends what you want exactly but something like this works:

<asp:Button ID="Cancel" Text="Cancel" runat="server" OnClientClick="alert('Hello');" />

But for your case you would of course have:

<asp:Button ID="Cancel" Text="Cancel" runat="server" OnClientClick="window.history.go(-1); return false;" />

The return false cancels the submit otherwise the page would do a post.

Is this enough for what you need?
Avatar of jn1480
jn1480
Flag of United States of America image

ASKER

Just about - but the code I am executing is:
    Protected Sub fvPage_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewCommandEventArgs) Handles fvPage.ItemCommand
        If e.CommandName = "Cancel" Then
            Response.Redirect("Pages.aspx")
        End If
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of daveamour
daveamour
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of jn1480
jn1480
Flag of United States of America image

ASKER

Thanks! A little experimenting and it works!
Avatar of jn1480
jn1480
Flag of United States of America image

ASKER

Thanks!
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo