history back in C#

Posted on 2007-08-01
Medium Priority
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
  • 2
  • 2
LVL 10

Expert Comment

ID: 19612583
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

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

Accepted Solution

Nash2334 earned 2000 total points
ID: 19612873
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

ID: 19612891

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

Take care

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
If you are looking for an automated tool which can generate reports for Outlook emails and other items from PST file, then you can go for Kernel PST Reporter tool. The reports which are created by this tool are helpful to analyze and understand PST …
Watch the video to know the simple way to remove or recover or reset lost or forgotten passwords of Outlook PST file. With Kernel Outlook Password Recovery tool such operation is very easy to perform. It is a freeware with limitation to use with 500…
Suggested Courses

607 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