Client Side Submit NOT Postback

Discussion in 'ASP .Net' started by Jim Duncan, Oct 22, 2004.

  1. Jim Duncan

    Jim Duncan Guest

    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>

    -------------------------------------------

    Thanks,
    Jim
     
    Jim Duncan, Oct 22, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:eGZ2sE%...
    > 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>
    >
    > -------------------------------------------
    >
    > Thanks,
    > Jim
    >
    >
     
    Ken Dopierala Jr., Oct 22, 2004
    #2
    1. Advertising

  3. Jim Duncan

    Jim Duncan Guest

    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." <> wrote in message
    news:u2wjTn%...
    > 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" <> wrote in message
    > news:eGZ2sE%...
    >> 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>
    >>
    >> -------------------------------------------
    >>
    >> Thanks,
    >> Jim
    >>
    >>

    >
    >
     
    Jim Duncan, Oct 22, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U3Jpbmk=?=

    Client Side changes not refecting server side label

    =?Utf-8?B?U3Jpbmk=?=, Feb 19, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    736
    =?Utf-8?B?YWpheA==?=
    Feb 21, 2004
  2. Valerian John
    Replies:
    6
    Views:
    5,146
    Valerian John
    May 17, 2004
  3. Boss302
    Replies:
    0
    Views:
    1,082
    Boss302
    Nov 21, 2006
  4. Bogdan
    Replies:
    2
    Views:
    677
    Bogdan
    Jun 9, 2008
  5. Zoe Hart
    Replies:
    1
    Views:
    388
    Scott Wisniewski
    Jan 8, 2004
Loading...

Share This Page