Back to page you called

Asked

Viewed 1,728 times

0

Is there any way I can make a code on a button come out, make me return to the page you called? Fixing the page does not give, because this page(query process) is called several other.

I did this and you’re making a mistake:

<span id="sair">
                    <asp:LinkButton ID="sairbutton" Text="[x] sair" runat="server" 
                    onclick="history.go(-1);" />
                </span>

Error:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS1026: ) expected

Source Error:


Line 643:               &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Line 644:               <span id="sair">
Line 645:                   <asp:LinkButton ID="sairbutton" Text="[x] sair" runat="server" 
Line 646:                   onclick="history.go(-1);" />
Line 647:               </span>

He says there’s a ")" missing, but where do I put it?

It does not rotate. No more error, but it does not work. My script.

<script type="text/javascript">
        function voltarPagina() {
            history.go(-1);
        }
    </script>

My Asp.net

<span id="sair">
                    <asp:LinkButton ID="sairbutton" Text="[x] sair" runat="server" 
                    OnClientClick="voltarPagina();" />
                </span>

No mistake, but do not go back to the page you called, remains on the same page.

  • Webform. It cannot be Response.Redirect(url);

  • Passing the description of the page called to the "process query" page and clicking that quit button give a Response.Redirect to the value received in the description of the page called. Do you have any impediment to that?

  • I can’t fix the return url, because with redirect I would have to define a page, but this page is called other so I can’t fix it by redirect. I think there’s something in javascript, like a back or something.

  • He tried with history.back() ?

  • Rectify Linkbutton and test with: <input action="action" type="button" value="[x] quit" onclick="history.go(-1);" />

3 answers

2

You can make the call via javascript:

<input action="action" type="button" value="Sair" onclick="history.go(-1);" />

The function can also be used:

history.back()

If you want to call a Linkbutton:

<asp:LinkButton ID="sairbutton" Text="[x] sair" runat="server" 
     OnClientClick="voltarPagina();" />

<script type="text/javascript">
function voltarPagina()
{
    history.go(-1);
}
</script>
  • I made an edit to show the error that gives.

  • @pnet updated in case you need to call a Linkbutton

  • It didn’t work. I made a new edit to tell you what’s going on.

0

To include a response using C#, you can do this using the property Urlreferrer.

Example :

// static variable
static string prevPage = String.Empty;

protected void Page_Load(object sender, EventArgs e)
{
     if( !IsPostBack )
     {
         prevPage = Request.UrlReferrer.ToString();
     }

 }

 protected void Button1_Click(object sender, EventArgs e)
 {
      Response.Redirect(prevPage);
 }

But use the Urlreferrer sparingly, as it uses the header HTTP_REFERER, and some antivirus and browser extensions may delete this header from the request.

0

I think the problem was in Linkbutton. I changed it and it worked.

<a href='javascript:history.go(-1)'>Voltar a pagina Anterior</a>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.