go back to previous page when Cancel button hit

Discussion in 'ASP .Net' started by wiewiek@gmail.com, May 6, 2005.

  1. Guest

    Is there a way to go back to the previous page when a button (Cancel
    button) is hot? It's an ASP control.

    Thanks
     
    , May 6, 2005
    #1
    1. Advertising

  2. > Is there a way to go back to the previous page when a button (Cancel
    > button) is hot? It's an ASP control.


    You mean "hit?" I will presume that the title is correct and that your
    message has a typo.

    It will be a little tricky, as we're dealing with an ASP.Net WebForm here,
    and very likely, the "previous page" will be the same page (if it has posted
    back) in your browser's history. What you would need to do is to keep track
    of the "previous page" by storing it's URL (Request.UrlReferer) in ViewState
    when the page is initially loaded, and only then. Thus, the URL of the
    "previous page" will be persisted in ViewState across postbacks.

    From there, it's a simple matter of handling the OnClick event of the
    Control with a Response.Redirect to that URL.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    What You Seek Is What You Get.

    <> wrote in message
    news:...
    > Is there a way to go back to the previous page when a button (Cancel
    > button) is hot? It's an ASP control.
    >
    > Thanks
    >
     
    Kevin Spencer, May 6, 2005
    #2
    1. Advertising

  3. Guest Guest

    If you're just looking to go back, you can just add an attribute with
    JavaScript to save you the trouble of handling the postback:

    \\\
    private void Page_Load(object sender, System.EventArgs e)
    {
    // Add attribute to go back one page.
    btnCancel.Attributes.Add("onClick", "history.back(); return false;");
    }
    ///

    Note that you must include the "return false;" snippet as well to keep the
    page from submitting. This is needed because ASP.NET buttons translate into
    submit buttons in the rendered HTML code at the browser.

    Hope this helps!

    Eric


    <> wrote in message
    news:...
    > Is there a way to go back to the previous page when a button (Cancel
    > button) is hot? It's an ASP control.
    >
    > Thanks
    >
     
    Guest, May 6, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alan Wang

    hit IE back button

    Alan Wang, Aug 31, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    589
    Alan Wang
    Sep 1, 2005
  2. yasin
    Replies:
    1
    Views:
    606
    Karl Seguin [MVP]
    Apr 20, 2006
  3. Eric
    Replies:
    9
    Views:
    1,035
    Blinky the Shark
    May 30, 2006
  4. CK
    Replies:
    9
    Views:
    406
    Jerry Rasmussen
    Oct 19, 2006
  5. Replies:
    0
    Views:
    167
Loading...

Share This Page