Back button (.net) generated not working (Repost)

S

ShaneFowlkes

I created a couple of quick test pages and to my surprise, these do not work
either. When I click "Go Back" on test2.aspx, nothing happens. Ideas??
Surely I must be missing something obvious.....

Thanks


PAGE 1 - test.aspx
<%@ Page Language="VB" %>

<script runat="server">

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)

Response.Redirect("test2.aspx")

End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form runat="server">

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Go" />

</form>

</body>

</html>




PAGE 2 - test2.aspx
<%@ Page Language="VB" %>

<script runat="server">

Sub page_load(ByVal Sender As Object, ByVal E As EventArgs)

Button1.Attributes.Add("onclick", "javascript:history.go(-1);")

End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form runat="server">

<asp:Button ID="Button1" runat="server" Text="Go Back" />

</form>

</body>

</html>






**********************************************
Original post:


Somethinng odd is happening. I have a form button and on page load, I add a
javascript "back" function to this button. Like so:

btnCancel.Attributes.Add("onclick", "javascript:window.history.go(-1);")

<asp:Button ID="btnCancel" runat="server" Text="Cancel and go back." />

This generates the following html when rendered:

<input type="submit" name="btnCancel" value="Cancel and go back."
onclick="javascript:window.history.go(-1);" id="btnCancel" />

Yet, it doesn't work in IE6 or FF 1.5. Nothing happens. The page just
seems to post to itself. I've also tried changing the history.go value
to -2 and still get the same effect.

Any ideas? I'm using asp.net 2 (vb)

Thanks
 
B

bruce barker \(sqlwork.com\)

you go back button is doing two navigations. one the history request and the
other the original submit. you need to cancel the submit

Button1.Attributes.Add("onclick", "javascript:history.go(-1);return
false;")

or use an anchor, or regualr button, not submit button.

-- bruce (sqlwork.com)
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top