history back in C#

Posted on 2007-08-01
Last Modified: 2008-01-09
Hi there

Wonder if you can help me?

I have the following method

protected void editor_CancelClicked(object sender, EventArgs e)

Please note, this isnt a button, im using a 3rd party control, and they've given me the method above.

What Id like is, if the user click on the item, it should run the editor_CancelClicked method, what it should do is go back 1 screen. Like  history.go(-1). I need some code in the {} that will for fill history.go(-1).

Question by:mousemat24
    LVL 10

    Expert Comment

    The javascript method to which you refer can be written to the page, but this will occur after the postback, essentially taking you right back to where you started.

    Given that, you will need to find some sort of persistence mechanism by which you can access that information from C# on the server side.  You can pass the referrer into the page itself via the querystring and access it that way, set a session variable, etc.

    If you want to get ambitious you can try to access the history via the file system, which seems like overkill.

    Author Comment

    "You can pass the referrer" - how do you do that Nash2334?
    LVL 10

    Accepted Solution

    Let's assume that the page that contains your "editor" control is called EditorPage.aspx.  Let's assume that the page that references EditorPage.aspx is ViewerPage.aspx.  Whatever mechanism that is used to get from ViewerPage.aspx to EditorPage.aspx needs to tell EditorPage.aspx where to send the user if the cancel is clicked (let's say CancelPage.aspx).

    So in ViewerPage.aspx, we have a link, button etc. that takes us to EditorPage.aspx.  In the link that takes us to the EditorPage.aspx (where the editor control lives), we can embed the url in the redirect.


    Once  EditorPage is loaded, all controls will have access to the querystring.  When editor_CancelClicked is not invoked, we can access the url we want to go to via the querystring.

    protected void editor_CancelClicked(object sender, EventArgs e)
          string url = string.Format("{0}.aspx", Request.QueryString["cancelurl"].ToString());

    You can also set a session variable if you do not want to use the QueryString.

    Author Comment


    Thanks for that, that very helpful!! :-)

    Take care

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Suggested Solutions

    Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
    Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now