Client Side Submit NOT Postback

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>
 
K

Ken Dopierala Jr.

Hi Jim,

Just create a hidden input field. When you want to ignore any postback
stuff set the value to 1 and test for that otherwise treat it as a postback.
Good luck! Ken.
 
J

Jim Duncan

Thanks, Ken.

I think the problem though is that I WANT it to be considered a postback but
it isn't. Probably because it's coming from a form that is not runat=server.

In other words, the SmartNavigation type stuff is not working. Clicking back
after a submit reloads the form instead of going to the previous page.

Thanks again,
Jim


Ken Dopierala Jr. said:
Hi Jim,

Just create a hidden input field. When you want to ignore any postback
stuff set the value to 1 and test for that otherwise treat it as a
postback.
Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

Jim Duncan said:
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>
 

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

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top