Back in ASP.NET - C#

Hey guys

I have a page with a button on it that says back. When clicked i want it to do the same as the back button of the browser. How would i do this?

I would usually do it like this, but it doesnt work. Is there any other way or am i maybe doing something wrong?

Response.Write("<SCRIPT LANGUAGE=\\"JavaScript\\">");
Response.Write("window.history.back()");
Response.Write("</script>");

All this does in reload the page

Thanks

ASP.NET has a function to write Javascript to a client now, have a look at RegisterClientScriptBlock

:slight_smile:

Don’t use asp.net for everything. In this case just do a plain html button with an onclick=“window.history.back(); return true;” attribute.

Hey

None of these methods work. I dnt know why and i need to fix it. :frowning:

Thanks 4 the help

works for me:

<INPUT type=“button” value=“Button” onclick=“window.history.back(); return true;”>

Thats weird. It doesnt for me. I copied your code exactally.

If i put a normal javascript in the head of the page like this

<script language="javascript" id="back">
window.alert("Test")
</script>

and call it like this: onclick=“back”

But it runs the script on page load and not when i click the button. Any ideas y its doing this?

yeah. Scripts in scriptblocks are supposed to run inline with the rendering. Try

<script language="javascript">
function back() {
    window.alert("Test");
}
</script>

Hey

That still didnt work, but i got it working. I done this

onclick="history.go(-1)"

It works perfect.

Thanks for all the help guys

I appreciate it :smiley: