back to calling page

J

Julia

Hi
I am developing a composite control, so I am writing all labels, button etc
in code. In my composite control I have a button and when it is clicked I
would like to go back to the calling page. This should be like using the back
button in the internet explorer. How can I do this.

Thanks
Julia
 
M

mnichols

Client-side javascript:
<input type=button value="Go Back" onclick="history.go(-1)">
 
J

Julia

Hi
thanks for the answer but I am not sure I understand how to do this. I am
writing all my component in the *.cs file, and I thought I was suppose to
write som code in the Click event to handle this.

I have a search page where the user can serch for products. When the user
clicks a product a detail page opens. The detail page contains my Composite
Control, and the Composite Control contains a button with the text "Back to
Search". When this button is pressed the Serach page should be opened again.
So this is the event that should open the Search page:

void btnBackToSearch_Click(object sender, EventArgs e)
{
//What can I write here to open the search page?
}

Thanks
Julia
 
S

Steve C. Orr [MVP, MCSD]

If you somehow store the name of the calling page (maybe in session state or
by posting it?) then you can simply Response.Redirect back to the page.

Or, a simple approach like this *might* just do the trick:
Response.Write("<script language='JavaScript'>history.go(-1)</script>");
 
J

Julia

Hi Steve,
and thanks for the answer. I have the name of the calling page, but as I
answered to mnichols I dont understand how to use it. The problem is that I
am writing all controls in code, I only use the *.cs file, so I would like to
do the call to the previous page in the click event of my button. This is the
event:

void btnBackToSearch_Click(object sender, EventArgs e)
{
//What can I write here to open the search page?
}

Do you know what to write in the event to go back to the calling page?

Thanks,
Julia
 
P

Prakash V

use btnBackToSearch.Attributes.Add("onclick","history.back()");

Regards,
Prakash.V
 
A

Alessandro Zifiglio

hi Julia,
Response.Redirect("thePageWhereIwantToGo.aspx"); is probaby what you are
looking for.
If you are not working in your codebehind for the webform(that inherits
page) but simply in a class file(this can be true if you are working with
custom controls for eg.) then you can use the HttpContext to get to the
Response object and call Response.Redirect like this :
HttpContext.Current.Response.Redirect("thePageWhereIwantToGo.aspx");
More here :
http://msdn2.microsoft.com/en-us/system.web.httpcontext.response.aspx

Alessandro Zifiglio
 
A

Alessandro Zifiglio

Julia, by the way, since you never mentioned what control or class you are
inheriting if any, if for eg. you were inheriting Control, WebControl,
CompositeControl etc..then the HttpContext is already exposed as a
property(Context), so simply calling the Context property which exposes
"HttpContext" object will be just fine. So you will be doing
this.Context.Current.Response.Redirect(.....).. and so on :)

Regards,
Alessandro Zifiglio
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top