Hi,
I am working on a web project and using Details View to insert new records. The problem is when I click cancel and then try to refresh page it shows dialog box saying

To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier.

When I was searching on web to prevent this solution given was to use Response.Redirect to prevent this dialog box. But I am already using the same when user clicks on Cancel link. Following is my code

protected void DetailView_ItemCommand(object sender, DetailsViewCommandEventArgs e)
    {
        if (e.CommandName == "Cancel")
        {
            Response.Redirect("~/Authors.aspx");
        }
    }

I want to redirect to same page when user clicks on the Cancel link and stop the dialog box to appear. And in some other cases to prevent the reposting the same data on refresh.

Member Avatar for LastMitch

I want to redirect to same page when user clicks on the Cancel link and stop the dialog box to appear. And in some other cases to prevent the reposting the same data on refresh.

Why is there a symbol ~ here:

Response.Redirect("~/Authors.aspx");

Can you explaing to me why?

Read this:

http://msdn.microsoft.com/en-us/library/ms524309%28v=vs.90%29.aspx

If you need to add a symbol ~ then read this:

http://msdn.microsoft.com/en-us/library/ms526004%28v=vs.90%29.aspx

This will explain and show you how to add an expression

@LastMitch --

"~" (Tilde) is a special character that is used to set URL paths for ASP.NET Server controls and this character instructs ASP.NET at run time to resolve the relative path of the server control.

If you look at the source code generated by the ASP.NET engine you won't see this character.

Member Avatar for LastMitch

If you look at the source code generated by the ASP.NET engine you won't see this character.

Thanks for explanation! It's good know. I still have alot to learn.

Member Avatar for LastMitch

To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier.

You can try HttpRedirect since the browser is preventing this to work (does happend to other browsers?):

http://msdn.microsoft.com/en-us/library/ms525695%28v=vs.90%29.aspx

You can try HttpRedirect since the browser is preventing this to work

I was not able to make it work, sorry.

does happend to other browsers?):

Yes it happens in every browser(Chrome, IE, Firefox).

I don't know but maybe I am not able to put this in right words. Everywhere solution was to use Responce.Redirect but thats not working for me but yes I am searching for it.
And again if I am using a gridview with paging enabled, I click on page 3 and now if I try to refresh it will show that pop up and in this case if I redirect to same page it will take me to the first page of gridview(Correct me if I am wrong as it never worked so I don't know). I think there will be more simple solution to this and I am missing proper keywords to search for it.

Member Avatar for LastMitch

I click on page 3 and now if I try to refresh it will show that pop up and in this case if I redirect to same page it will take me to the first page of gridview(Correct me if I am wrong as it never worked so I don't know).

You did mislead me regarding not redirected in Firefox apparently it doesn't work for all browsers at all.

The way you explain it it seems like it's not reading Response.Redirect

Try read and follow the instruction to see it's connected:

http://support.microsoft.com/kb/307903

Then try this (I know this one is an old one but I do want to see an error):

http://support.microsoft.com/kb/159402

If you see this error:

Response object error 'ASP 0156 : 80004005
Header Error
/<page.asp>, line 9
The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content. 

Then it's good it means your Response.Redirect works then the issue is some place else.

I hope that I explained clearly.

Sorry for that. And yes I get this error after trying. The only problem is when redirecting to the same page.

Member Avatar for LastMitch

The only problem is when redirecting to the same page.

Try used this:

protected void DetailView_ItemCommand(object sender, DetailsViewCommandEventArgs e)
{
if (e.CommandName == "Cancel")
{
string myurl = "../Authors.aspx";
Response.Redirect(myurl);
}
}

or try this:

protected void DetailView_ItemCommand(object sender, DetailsViewCommandEventArgs e)
{
if (e.CommandName == "Cancel")
{
Response.Redirect("#Authors.aspx"); 
}
}

or try this:

protected void DetailView_ItemCommand(object sender, DetailsViewCommandEventArgs e)
{
if (e.CommandName == "Cancel")
{
Response.Redirect(Request.RawUrl);
}
}

If not doesn't work then you need to explain the path or show the path to see why it doesn;'t redirected:

~/Authors.aspx

Show the path not instead of this symbol

like for example:

 fold/Authors.aspx

or

 fold/fold/Authors.aspx
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.