problem with postback

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Harry

    #1

    problem with postback

    Hi,

    This aspx page (let's call it thispage.aspx) fetches data from a
    sqldatasource, then performs several things (in code-behind) and, to
    simplify, passes data from code-behind via a hiddenfield to a javascript in
    the aspx file. This javascript performs things and finally send data via a
    form to another database.

    My problem is that when the page is postback (with this java-line:
    document.getEle mentById("ins") .action="thispa ge.aspx"), instead of
    performing the code after "If Page.IsPostBack Then", it shows the original
    aspx file again.

    Any idea what i have to change to do what i want to do?
    Thanks
    Harry


    aspx file:
    -------
    <form id="form1" runat="server">
    <asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
    ConnectionStrin g="Provider = ... ; Data Source =...;">
    </asp:SqlDataSour ce>
    <asp:HiddenFiel d ID="HiddenField 1" runat="server" />
    </form>

    <form id="ins" style="width:75 0px;background-color:Gray" method="post">
    <input id="sql" name="sql" type="hidden" />
    <input id="conn" name="conn" type="hidden" />
    <input runat="server" id="Submit1" type="button" value="Klik hier om
    te bewaren" onclick="sendto db()"/>
    </form>

    <script language="javas cript" type="text/javascript">

    function sendtodb()
    {
    var nfieldout=docum ent.getElementB yId("hiddenfiel d1").value
    ......
    ......
    document.getEle mentById("sql") .value=inscomm
    document.getEle mentById("conn" ).value=conn
    document.getEle mentById("ins") .action="thispa ge.aspx"
    document.getEle mentById("ins") .submit()
    return true;
    </script>


    code-behind
    -----------
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArg s) Handles Me.Load
    If Page.IsPostBack Then
    Dim conn, sql
    sql = Request.Form("s ql")
    conn = Request.Form("c onn")
    Dim oConnection As OleDbConnection
    Dim sConnection As String
    oConnection = New OleDbConnection ()
    Dim comd As OleDbCommand
    sConnection = conn
    oConnection.Con nectionString = sConnection
    oConnection.Ope n()
    comd = New OleDbCommand(sq l, oConnection)
    comd.ExecuteNon Query()
    oConnection.Clo se()
    else
    HiddenField1.Va lue = "1"
    .......
    .......
    end if
    end sub


  • =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

    #2
    RE: problem with postback

    Harry,
    From what you have written, it *sounds* like what you want to do is a
    cross-page postback. Look up the term "cross-page postback" and you will find
    examples and description of how to use.
    Peter

    --
    Site: http://www.eggheadcafe.com
    UnBlog: http://petesbloggerama.blogspot.com
    Short urls & more: http://ittyurl.net




    "Harry" wrote:
    Hi,
    >
    This aspx page (let's call it thispage.aspx) fetches data from a
    sqldatasource, then performs several things (in code-behind) and, to
    simplify, passes data from code-behind via a hiddenfield to a javascript in
    the aspx file. This javascript performs things and finally send data via a
    form to another database.
    >
    My problem is that when the page is postback (with this java-line:
    document.getEle mentById("ins") .action="thispa ge.aspx"), instead of
    performing the code after "If Page.IsPostBack Then", it shows the original
    aspx file again.
    >
    Any idea what i have to change to do what i want to do?
    Thanks
    Harry
    >
    >
    aspx file:
    -------
    <form id="form1" runat="server">
    <asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
    ConnectionStrin g="Provider = ... ; Data Source =...;">
    </asp:SqlDataSour ce>
    <asp:HiddenFiel d ID="HiddenField 1" runat="server" />
    </form>
    >
    <form id="ins" style="width:75 0px;background-color:Gray" method="post">
    <input id="sql" name="sql" type="hidden" />
    <input id="conn" name="conn" type="hidden" />
    <input runat="server" id="Submit1" type="button" value="Klik hier om
    te bewaren" onclick="sendto db()"/>
    </form>
    >
    <script language="javas cript" type="text/javascript">
    >
    function sendtodb()
    {
    var nfieldout=docum ent.getElementB yId("hiddenfiel d1").value
    ......
    ......
    document.getEle mentById("sql") .value=inscomm
    document.getEle mentById("conn" ).value=conn
    document.getEle mentById("ins") .action="thispa ge.aspx"
    document.getEle mentById("ins") .submit()
    return true;
    </script>
    >
    >
    code-behind
    -----------
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArg s) Handles Me.Load
    If Page.IsPostBack Then
    Dim conn, sql
    sql = Request.Form("s ql")
    conn = Request.Form("c onn")
    Dim oConnection As OleDbConnection
    Dim sConnection As String
    oConnection = New OleDbConnection ()
    Dim comd As OleDbCommand
    sConnection = conn
    oConnection.Con nectionString = sConnection
    oConnection.Ope n()
    comd = New OleDbCommand(sq l, oConnection)
    comd.ExecuteNon Query()
    oConnection.Clo se()
    else
    HiddenField1.Va lue = "1"
    .......
    .......
    end if
    end sub
    >
    >
    >

    Comment

    • Harry

      #3
      Re: problem with postback

      Peter, thanks for replying.

      Maybe my explanation was not good, but i don't think it's cross-page
      postback, since the 'action' method in javascript of the form
      (document.getEl ementByI("ins") .action="thispa ge.aspx") refers to itself
      ("thispage.aspx "). The whole code here below is contained in "thispage.a spx"
      and "thispage.aspx. vb".


      "Peter Bromberg [C# MVP]" <pbromberg@yaho o.yabbadabbadoo .comschreef in
      bericht news:605297C0-E8BB-4DB5-B7E8-405B98B69924@mi crosoft.com...
      Harry,
      From what you have written, it *sounds* like what you want to do is a
      cross-page postback. Look up the term "cross-page postback" and you will
      find
      examples and description of how to use.
      Peter
      >
      --
      Site: http://www.eggheadcafe.com
      UnBlog: http://petesbloggerama.blogspot.com
      Short urls & more: http://ittyurl.net
      >
      >
      >
      >
      "Harry" wrote:
      >
      >Hi,
      >>
      >This aspx page (let's call it thispage.aspx) fetches data from a
      >sqldatasourc e, then performs several things (in code-behind) and, to
      >simplify, passes data from code-behind via a hiddenfield to a javascript
      >in
      >the aspx file. This javascript performs things and finally send data via
      >a
      >form to another database.
      >>
      >My problem is that when the page is postback (with this java-line:
      >document.getEl ementById("ins" ).action="thisp age.aspx"), instead of
      >performing the code after "If Page.IsPostBack Then", it shows the
      >original
      >aspx file again.
      >>
      >Any idea what i have to change to do what i want to do?
      >Thanks
      >Harry
      >>
      >>
      >aspx file:
      >-------
      > <form id="form1" runat="server">
      > <asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
      >ConnectionStri ng="Provider = ... ; Data Source =...;">
      ></asp:SqlDataSour ce>
      > <asp:HiddenFiel d ID="HiddenField 1" runat="server" />
      > </form>
      >>
      > <form id="ins" style="width:75 0px;background-color:Gray" method="post">
      > <input id="sql" name="sql" type="hidden" />
      > <input id="conn" name="conn" type="hidden" />
      > <input runat="server" id="Submit1" type="button" value="Klik hier
      >om
      >te bewaren" onclick="sendto db()"/>
      > </form>
      >>
      ><script language="javas cript" type="text/javascript">
      >>
      >function sendtodb()
      >{
      >var nfieldout=docum ent.getElementB yId("hiddenfiel d1").value
      >......
      >......
      >document.getEl ementById("sql" ).value=inscomm
      >document.getEl ementById("conn ").value=co nn
      >document.getEl ementById("ins" ).action="thisp age.aspx"
      >document.getEl ementById("ins" ).submit()
      >return true;
      ></script>
      >>
      >>
      >code-behind
      >-----------
      > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
      >System.EventAr gs) Handles Me.Load
      >If Page.IsPostBack Then
      > Dim conn, sql
      > sql = Request.Form("s ql")
      > conn = Request.Form("c onn")
      > Dim oConnection As OleDbConnection
      > Dim sConnection As String
      > oConnection = New OleDbConnection ()
      > Dim comd As OleDbCommand
      > sConnection = conn
      > oConnection.Con nectionString = sConnection
      > oConnection.Ope n()
      > comd = New OleDbCommand(sq l, oConnection)
      > comd.ExecuteNon Query()
      > oConnection.Clo se()
      >else
      >HiddenField1.V alue = "1"
      >.......
      >.......
      >end if
      >end sub
      >>
      >>
      >>

      Comment

      • bruce barker

        #4
        Re: problem with postback

        IsPostBack just checks for the "__Viewstat e" hidden field in the
        postback form fields. as you are submitting a different form on the page
        then the one containing the viewstate, the viewstate hidden field is not
        included in the postback data


        -- bruce (sqlwork.com)

        Harry wrote:
        Peter, thanks for replying.
        >
        Maybe my explanation was not good, but i don't think it's cross-page
        postback, since the 'action' method in javascript of the form
        (document.getEl ementByI("ins") .action="thispa ge.aspx") refers to itself
        ("thispage.aspx "). The whole code here below is contained in "thispage.a spx"
        and "thispage.aspx. vb".
        >
        >
        "Peter Bromberg [C# MVP]" <pbromberg@yaho o.yabbadabbadoo .comschreef in
        bericht news:605297C0-E8BB-4DB5-B7E8-405B98B69924@mi crosoft.com...
        >Harry,
        >From what you have written, it *sounds* like what you want to do is a
        >cross-page postback. Look up the term "cross-page postback" and you will
        >find
        >examples and description of how to use.
        >Peter
        >>
        >--
        >Site: http://www.eggheadcafe.com
        >UnBlog: http://petesbloggerama.blogspot.com
        >Short urls & more: http://ittyurl.net
        >>
        >>
        >>
        >>
        >"Harry" wrote:
        >>
        >>Hi,
        >>>
        >>This aspx page (let's call it thispage.aspx) fetches data from a
        >>sqldatasource , then performs several things (in code-behind) and, to
        >>simplify, passes data from code-behind via a hiddenfield to a javascript
        >>in
        >>the aspx file. This javascript performs things and finally send data via
        >>a
        >>form to another database.
        >>>
        >>My problem is that when the page is postback (with this java-line:
        >>document.getE lementById("ins ").action="this page.aspx"), instead of
        >>performing the code after "If Page.IsPostBack Then", it shows the
        >>original
        >>aspx file again.
        >>>
        >>Any idea what i have to change to do what i want to do?
        >>Thanks
        >>Harry
        >>>
        >>>
        >>aspx file:
        >>-------
        >> <form id="form1" runat="server">
        >> <asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
        >>ConnectionStr ing="Provider = ... ; Data Source =...;">
        >></asp:SqlDataSour ce>
        >> <asp:HiddenFiel d ID="HiddenField 1" runat="server" />
        >> </form>
        >>>
        >> <form id="ins" style="width:75 0px;background-color:Gray" method="post">
        >> <input id="sql" name="sql" type="hidden" />
        >> <input id="conn" name="conn" type="hidden" />
        >> <input runat="server" id="Submit1" type="button" value="Klik hier
        >>om
        >>te bewaren" onclick="sendto db()"/>
        >> </form>
        >>>
        >><script language="javas cript" type="text/javascript">
        >>>
        >>function sendtodb()
        >>{
        >>var nfieldout=docum ent.getElementB yId("hiddenfiel d1").value
        >>......
        >>......
        >>document.getE lementById("sql ").value=inscom m
        >>document.getE lementById("con n").value=co nn
        >>document.getE lementById("ins ").action="this page.aspx"
        >>document.getE lementById("ins ").submit()
        >>return true;
        >></script>
        >>>
        >>>
        >>code-behind
        >>-----------
        >> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
        >>System.EventA rgs) Handles Me.Load
        >>If Page.IsPostBack Then
        >> Dim conn, sql
        >> sql = Request.Form("s ql")
        >> conn = Request.Form("c onn")
        >> Dim oConnection As OleDbConnection
        >> Dim sConnection As String
        >> oConnection = New OleDbConnection ()
        >> Dim comd As OleDbCommand
        >> sConnection = conn
        >> oConnection.Con nectionString = sConnection
        >> oConnection.Ope n()
        >> comd = New OleDbCommand(sq l, oConnection)
        >> comd.ExecuteNon Query()
        >> oConnection.Clo se()
        >>else
        >>HiddenField1. Value = "1"
        >>.......
        >>.......
        >>end if
        >>end sub
        >>>
        >>>
        >>>
        >
        >

        Comment

        • Harry

          #5
          Re: problem with postback

          Thanks for the explanation.
          Now, if you would have a solution in mind for that, it would be great.


          "bruce barker" <nospam@nospam. comschreef in bericht
          news:%23g4bzSeh HHA.4936@TK2MSF TNGP04.phx.gbl. ..
          IsPostBack just checks for the "__Viewstat e" hidden field in the postback
          form fields. as you are submitting a different form on the page then the
          one containing the viewstate, the viewstate hidden field is not included
          in the postback data
          >
          >
          -- bruce (sqlwork.com)
          >
          Harry wrote:
          >Peter, thanks for replying.
          >>
          >Maybe my explanation was not good, but i don't think it's cross-page
          >postback, since the 'action' method in javascript of the form
          >(document.getE lementByI("ins" ).action="thisp age.aspx") refers to itself
          >("thispage.asp x"). The whole code here below is contained in
          >"thispage.aspx " and "thispage.aspx. vb".
          >>
          >>
          >"Peter Bromberg [C# MVP]" <pbromberg@yaho o.yabbadabbadoo .comschreef in
          >bericht news:605297C0-E8BB-4DB5-B7E8-405B98B69924@mi crosoft.com...
          >>Harry,
          >>From what you have written, it *sounds* like what you want to do is a
          >>cross-page postback. Look up the term "cross-page postback" and you will
          >>find
          >>examples and description of how to use.
          >>Peter
          >>>
          >>--
          >>Site: http://www.eggheadcafe.com
          >>UnBlog: http://petesbloggerama.blogspot.com
          >>Short urls & more: http://ittyurl.net
          >>>
          >>>
          >>>
          >>>
          >>"Harry" wrote:
          >>>
          >>>Hi,
          >>>>
          >>>This aspx page (let's call it thispage.aspx) fetches data from a
          >>>sqldatasourc e, then performs several things (in code-behind) and, to
          >>>simplify, passes data from code-behind via a hiddenfield to a
          >>>javascript in
          >>>the aspx file. This javascript performs things and finally send data
          >>>via a
          >>>form to another database.
          >>>>
          >>>My problem is that when the page is postback (with this java-line:
          >>>document.get ElementById("in s").action="thi spage.aspx"), instead of
          >>>performing the code after "If Page.IsPostBack Then", it shows the
          >>>original
          >>>aspx file again.
          >>>>
          >>>Any idea what i have to change to do what i want to do?
          >>>Thanks
          >>>Harry
          >>>>
          >>>>
          >>>aspx file:
          >>>-------
          >>> <form id="form1" runat="server">
          >>> <asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
          >>>ConnectionSt ring="Provider = ... ; Data Source =...;">
          >>></asp:SqlDataSour ce>
          >>> <asp:HiddenFiel d ID="HiddenField 1" runat="server" />
          >>> </form>
          >>>>
          >>> <form id="ins" style="width:75 0px;background-color:Gray"
          >>>method="post ">
          >>> <input id="sql" name="sql" type="hidden" />
          >>> <input id="conn" name="conn" type="hidden" />
          >>> <input runat="server" id="Submit1" type="button" value="Klik hier
          >>>om
          >>>te bewaren" onclick="sendto db()"/>
          >>> </form>
          >>>>
          >>><script language="javas cript" type="text/javascript">
          >>>>
          >>>function sendtodb()
          >>>{
          >>>var nfieldout=docum ent.getElementB yId("hiddenfiel d1").value
          >>>......
          >>>......
          >>>document.get ElementById("sq l").value=insco mm
          >>>document.get ElementById("co nn").value=co nn
          >>>document.get ElementById("in s").action="thi spage.aspx"
          >>>document.get ElementById("in s").submit()
          >>>return true;
          >>></script>
          >>>>
          >>>>
          >>>code-behind
          >>>-----------
          >>> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
          >>>System.Event Args) Handles Me.Load
          >>>If Page.IsPostBack Then
          >>> Dim conn, sql
          >>> sql = Request.Form("s ql")
          >>> conn = Request.Form("c onn")
          >>> Dim oConnection As OleDbConnection
          >>> Dim sConnection As String
          >>> oConnection = New OleDbConnection ()
          >>> Dim comd As OleDbCommand
          >>> sConnection = conn
          >>> oConnection.Con nectionString = sConnection
          >>> oConnection.Ope n()
          >>> comd = New OleDbCommand(sq l, oConnection)
          >>> comd.ExecuteNon Query()
          >>> oConnection.Clo se()
          >>>else
          >>>HiddenField1 .Value = "1"
          >>>.......
          >>>.......
          >>>end if
          >>>end sub
          >>>>
          >>>>
          >>>>
          >>

          Comment

          Working...