J
Jim Duncan
How can I make a client-side javascript form.submit() look enough like a
postback that the browser back button will not show the previous state of
the form and instead go to the previous page?
I have two forms on the page. The first is a server form (runat=server) and
contains a Repeater control. One of the columns contains a checkbox for each
row.
The second form has a hidden field that will contain a comma delimited
string of the values of the checkboxes that are checked. A link on the page
runs the script that creates the string of values and assigns it to the
value of the hidden field and then calls the submit() of the second form. A
second hidden field in this non-server form is used to flag a form postback.
This works, however clicking back after submitting the (non-server) form
doesn't go back to the previous page only to the previous state of the
current page.
Here's a skeletal version of the code:
<form runat=server>
<asp:Repeater runat=server>
....
<input type=checkbox name=myValue runat=server
value='<%DataBinder.Eval(Container.DataItem, "myValue")%>'>
....
</asp:Repeater>
</form>
<form action="myPage.aspx" method="post" id="myForm" name="myForm">
<input type="hidden" name="hdnPostBack" id="hdnPostBack" runat=server
value="y">
<input type="hidden" name="myValue" id="myValue" value="" runat=server>
</form>
<script language=javascript>
function doSubmit()
{
// code to build comma delimited string of values strValues
document.forms["myForm"].myValue.value = strValues;
document.forms["myForm"].submit();
}
</script>
<a href="javascript:doSubmit()">submit it</a>
postback that the browser back button will not show the previous state of
the form and instead go to the previous page?
I have two forms on the page. The first is a server form (runat=server) and
contains a Repeater control. One of the columns contains a checkbox for each
row.
The second form has a hidden field that will contain a comma delimited
string of the values of the checkboxes that are checked. A link on the page
runs the script that creates the string of values and assigns it to the
value of the hidden field and then calls the submit() of the second form. A
second hidden field in this non-server form is used to flag a form postback.
This works, however clicking back after submitting the (non-server) form
doesn't go back to the previous page only to the previous state of the
current page.
Here's a skeletal version of the code:
<form runat=server>
<asp:Repeater runat=server>
....
<input type=checkbox name=myValue runat=server
value='<%DataBinder.Eval(Container.DataItem, "myValue")%>'>
....
</asp:Repeater>
</form>
<form action="myPage.aspx" method="post" id="myForm" name="myForm">
<input type="hidden" name="hdnPostBack" id="hdnPostBack" runat=server
value="y">
<input type="hidden" name="myValue" id="myValue" value="" runat=server>
</form>
<script language=javascript>
function doSubmit()
{
// code to build comma delimited string of values strValues
document.forms["myForm"].myValue.value = strValues;
document.forms["myForm"].submit();
}
</script>
<a href="javascript:doSubmit()">submit it</a>