how to go from VB in a page to ASP in another page and come back

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

    how to go from VB in a page to ASP in another page and come back

    Hi,


    This is 'test.htm'
    ---------------

    <form name=totd>
    <input name="ud" type="hidden" value="" >
    </form>

    sub dag_onchange()
    'dag is a Select
    dat=dag.value
    if dat<>"99" then
    'pass that value to ASP file via a form
    document.getEle mentById("ud"). value=dat
    ins.action="tes t2.asp"
    ins.method="pos t"
    ins.submit

    'i need the value totd generated by 'test2.asp' and then come back and
    continue here ...
    if totd=0 then.
    ......
    end if
    .........
    end sub


    table 'test2.asp'
    --------------
    <%
    dat=request.for m("ud")
    set objdc = Server.CreateOb ject("ADODB.Con nection")
    objdc.Open("pro vider=Microsoft .Jet.OLEDB.4.0; Data Source
    =c:\access\test .mdb")
    sql = "select lcount(uur) as totdag from studres
    set rs=Server.Creat eObject("ADODB. recordset")
    rs.open sql, objdc, 3, 3
    rec=rs.recordco unt
    if rec > 0 then
    totd=rs.Fields( "totdag").V alue
    end if
    %>

    Now i would like to go back to 'test.asp' with the value of totd, and even
    in the sub dag_change() procedure
    ..
    Thanks for help
    André


  • J. Alan Rueckgauer

    #2
    Re: how to go from VB in a page to ASP in another page and come back


    "Andre" <aa@no.it> wrote in message
    news:eMspghsWEH A.1144@TK2MSFTN GP10.phx.gbl...[color=blue]
    > Hi,
    >
    >
    > This is 'test.htm'
    > ---------------
    >
    > <form name=totd>
    > <input name="ud" type="hidden" value="" >
    > </form>
    >
    > sub dag_onchange()
    > 'dag is a Select
    > dat=dag.value
    > if dat<>"99" then
    > 'pass that value to ASP file via a form
    > document.getEle mentById("ud"). value=dat
    > ins.action="tes t2.asp"
    > ins.method="pos t"
    > ins.submit
    >
    > 'i need the value totd generated by 'test2.asp' and then come back and
    > continue here ...
    > if totd=0 then.
    > .....
    > end if
    > ........
    > end sub
    >
    >
    > table 'test2.asp'
    > --------------
    > <%
    > dat=request.for m("ud")
    > set objdc = Server.CreateOb ject("ADODB.Con nection")
    > objdc.Open("pro vider=Microsoft .Jet.OLEDB.4.0; Data Source
    > =c:\access\test .mdb")
    > sql = "select lcount(uur) as totdag from studres
    > set rs=Server.Creat eObject("ADODB. recordset")
    > rs.open sql, objdc, 3, 3
    > rec=rs.recordco unt
    > if rec > 0 then
    > totd=rs.Fields( "totdag").V alue
    > end if
    > %>
    >
    > Now i would like to go back to 'test.asp' with the value of totd, and even
    > in the sub dag_change() procedure
    > .
    > Thanks for help
    > André
    >[/color]

    Andre --

    You can't call server-side script (as in an ASP script) from client-side
    event code without a third-party tool. You have to either post your form or
    get the desired script with a querystring for the server to know you want it
    to do something.

    You could do something like this in just one ASP:

    ** file test.asp **
    <% option explicit %>
    <%
    dim strMethod, cn, strSQL, rs, dat, totd, IsPostback

    ' initialize variables so their purpose is clear
    ' and you don't have problems later if they're not initialized
    IsPostback = False
    strMethod = ""
    dat = ""
    totd = CLng(0) ' since totd holds a long later on
    ' also guarantees totd has a long integer value even if it isn't
    changed

    with Request
    strMethod = LCase(.serverva riables("REQUES T_METHOD"))
    if strMethod = "post" then
    IsPostback = True
    ' Assuming you're using IIS 5 or later, you can use
    Server.Execute to call another script.
    ' However, for this example it'll be done in-line in this
    script.
    dat = .form("ud") ' you don't indicate just what 'dat' is used
    for
    set cn = createobject("A DODB.Connection ")
    set rs = createobject("A DODB.Recordset" )
    strSQL = "select count(uur) as totdag from studres" ' lcount??
    cn.Open("provid er=Microsoft.Je t.OLEDB.4.0; Data
    Source=c:\acces s\test.mdb")
    with rs
    .cursortype = adOpenStatic ' 3
    .locktype = adLockReadOnly ' 1
    .activeconnecti on = cn
    .open strSQL
    .activeconnecti on = nothing
    ' if you are only reading, always close the connection
    immediately
    ' only keep it open if you will be doing more work right
    then
    cn.close
    if .recordcount > 0 then
    ' no need to assign recordcount unless you will use it
    more than once
    totd = CLng(.Fields("t otdag").Value) ' casting numerics
    is a good idea
    end if
    .close
    end with
    set rs = nothing
    set cn = nothing
    end if
    end with
    %>
    <html>
    <head>
    </head>
    <body>
    <form <form name="totd" method="post">
    <input name="ud" type="hidden" value="">
    <% if 1 = 0 then %>
    comment: you can use the dropdown's change event as you had
    to do the assignment and submit, but you and just as easily get
    its value as .form("thedropd ownsname") from the script's
    request object
    <% end if %>
    </form>
    <% if IsPostback then %><br>The value of 'totd' is:&nbsp;<%=tot d%><br><%
    end if %>
    </body>
    </html>

    Alternatively, you could put your processing code in a Function within the
    script, or in another file containing common routines you use and use an
    #include directive in pages you want it.

    Alan


    Comment

    • Andre

      #3
      Re: how to go from VB in a page to ASP in another page and come back

      thanks ...

      "J. Alan Rueckgauer" <void@dev.nul > wrote in message
      news:upN4lseXEH A.644@tk2msftng p13.phx.gbl...[color=blue]
      >
      > "Andre" <aa@no.it> wrote in message
      > news:eMspghsWEH A.1144@TK2MSFTN GP10.phx.gbl...[color=green]
      > > Hi,
      > >
      > >
      > > This is 'test.htm'
      > > ---------------
      > >
      > > <form name=totd>
      > > <input name="ud" type="hidden" value="" >
      > > </form>
      > >
      > > sub dag_onchange()
      > > 'dag is a Select
      > > dat=dag.value
      > > if dat<>"99" then
      > > 'pass that value to ASP file via a form
      > > document.getEle mentById("ud"). value=dat
      > > ins.action="tes t2.asp"
      > > ins.method="pos t"
      > > ins.submit
      > >
      > > 'i need the value totd generated by 'test2.asp' and then come back and
      > > continue here ...
      > > if totd=0 then.
      > > .....
      > > end if
      > > ........
      > > end sub
      > >
      > >
      > > table 'test2.asp'
      > > --------------
      > > <%
      > > dat=request.for m("ud")
      > > set objdc = Server.CreateOb ject("ADODB.Con nection")
      > > objdc.Open("pro vider=Microsoft .Jet.OLEDB.4.0; Data Source
      > > =c:\access\test .mdb")
      > > sql = "select lcount(uur) as totdag from studres
      > > set rs=Server.Creat eObject("ADODB. recordset")
      > > rs.open sql, objdc, 3, 3
      > > rec=rs.recordco unt
      > > if rec > 0 then
      > > totd=rs.Fields( "totdag").V alue
      > > end if
      > > %>
      > >
      > > Now i would like to go back to 'test.asp' with the value of totd, and[/color][/color]
      even[color=blue][color=green]
      > > in the sub dag_change() procedure
      > > .
      > > Thanks for help
      > > André
      > >[/color]
      >
      > Andre --
      >
      > You can't call server-side script (as in an ASP script) from client-side
      > event code without a third-party tool. You have to either post your form[/color]
      or[color=blue]
      > get the desired script with a querystring for the server to know you want[/color]
      it[color=blue]
      > to do something.
      >
      > You could do something like this in just one ASP:
      >
      > ** file test.asp **
      > <% option explicit %>
      > <%
      > dim strMethod, cn, strSQL, rs, dat, totd, IsPostback
      >
      > ' initialize variables so their purpose is clear
      > ' and you don't have problems later if they're not initialized
      > IsPostback = False
      > strMethod = ""
      > dat = ""
      > totd = CLng(0) ' since totd holds a long later on
      > ' also guarantees totd has a long integer value even if it isn't
      > changed
      >
      > with Request
      > strMethod = LCase(.serverva riables("REQUES T_METHOD"))
      > if strMethod = "post" then
      > IsPostback = True
      > ' Assuming you're using IIS 5 or later, you can use
      > Server.Execute to call another script.
      > ' However, for this example it'll be done in-line in this
      > script.
      > dat = .form("ud") ' you don't indicate just what 'dat' is[/color]
      used[color=blue]
      > for
      > set cn = createobject("A DODB.Connection ")
      > set rs = createobject("A DODB.Recordset" )
      > strSQL = "select count(uur) as totdag from studres" '[/color]
      lcount??[color=blue]
      > cn.Open("provid er=Microsoft.Je t.OLEDB.4.0; Data
      > Source=c:\acces s\test.mdb")
      > with rs
      > .cursortype = adOpenStatic ' 3
      > .locktype = adLockReadOnly ' 1
      > .activeconnecti on = cn
      > .open strSQL
      > .activeconnecti on = nothing
      > ' if you are only reading, always close the connection
      > immediately
      > ' only keep it open if you will be doing more work right
      > then
      > cn.close
      > if .recordcount > 0 then
      > ' no need to assign recordcount unless you will use it
      > more than once
      > totd = CLng(.Fields("t otdag").Value) ' casting[/color]
      numerics[color=blue]
      > is a good idea
      > end if
      > .close
      > end with
      > set rs = nothing
      > set cn = nothing
      > end if
      > end with
      > %>
      > <html>
      > <head>
      > </head>
      > <body>
      > <form <form name="totd" method="post">
      > <input name="ud" type="hidden" value="">
      > <% if 1 = 0 then %>
      > comment: you can use the dropdown's change event as you had
      > to do the assignment and submit, but you and just as easily get
      > its value as .form("thedropd ownsname") from the script's
      > request object
      > <% end if %>
      > </form>
      > <% if IsPostback then %><br>The value of 'totd'[/color]
      is:&nbsp;<%=tot d%><br><%[color=blue]
      > end if %>
      > </body>
      > </html>
      >
      > Alternatively, you could put your processing code in a Function within the
      > script, or in another file containing common routines you use and use an
      > #include directive in pages you want it.
      >
      > Alan
      >
      >[/color]


      Comment

      • Andre

        #4
        Re: how to go from VB in a page to ASP in another page and come back

        but if i understand your code, the value from ASP is put outside the SUB. Is
        it not possible to get that value within the SUB dag_onchange(), because
        that value must be tested in the SUB and determines the visibility style of
        another SELECT in the same page etc ...
        If i get that value outside SUB dag_onchange, how can i make the other
        select visible?

        thanks again







        "J. Alan Rueckgauer" <void@dev.nul > wrote in message
        news:upN4lseXEH A.644@tk2msftng p13.phx.gbl...[color=blue]
        >
        > "Andre" <aa@no.it> wrote in message
        > news:eMspghsWEH A.1144@TK2MSFTN GP10.phx.gbl...[color=green]
        > > Hi,
        > >
        > >
        > > This is 'test.htm'
        > > ---------------
        > >
        > > <form name=totd>
        > > <input name="ud" type="hidden" value="" >
        > > </form>
        > >
        > > sub dag_onchange()
        > > 'dag is a Select
        > > dat=dag.value
        > > if dat<>"99" then
        > > 'pass that value to ASP file via a form
        > > document.getEle mentById("ud"). value=dat
        > > ins.action="tes t2.asp"
        > > ins.method="pos t"
        > > ins.submit
        > >
        > > 'i need the value totd generated by 'test2.asp' and then come back and
        > > continue here ...
        > > if totd=0 then.
        > > .....
        > > end if
        > > ........
        > > end sub
        > >
        > >
        > > table 'test2.asp'
        > > --------------
        > > <%
        > > dat=request.for m("ud")
        > > set objdc = Server.CreateOb ject("ADODB.Con nection")
        > > objdc.Open("pro vider=Microsoft .Jet.OLEDB.4.0; Data Source
        > > =c:\access\test .mdb")
        > > sql = "select lcount(uur) as totdag from studres
        > > set rs=Server.Creat eObject("ADODB. recordset")
        > > rs.open sql, objdc, 3, 3
        > > rec=rs.recordco unt
        > > if rec > 0 then
        > > totd=rs.Fields( "totdag").V alue
        > > end if
        > > %>
        > >
        > > Now i would like to go back to 'test.asp' with the value of totd, and[/color][/color]
        even[color=blue][color=green]
        > > in the sub dag_change() procedure
        > > .
        > > Thanks for help
        > > André
        > >[/color]
        >
        > Andre --
        >
        > You can't call server-side script (as in an ASP script) from client-side
        > event code without a third-party tool. You have to either post your form[/color]
        or[color=blue]
        > get the desired script with a querystring for the server to know you want[/color]
        it[color=blue]
        > to do something.
        >
        > You could do something like this in just one ASP:
        >
        > ** file test.asp **
        > <% option explicit %>
        > <%
        > dim strMethod, cn, strSQL, rs, dat, totd, IsPostback
        >
        > ' initialize variables so their purpose is clear
        > ' and you don't have problems later if they're not initialized
        > IsPostback = False
        > strMethod = ""
        > dat = ""
        > totd = CLng(0) ' since totd holds a long later on
        > ' also guarantees totd has a long integer value even if it isn't
        > changed
        >
        > with Request
        > strMethod = LCase(.serverva riables("REQUES T_METHOD"))
        > if strMethod = "post" then
        > IsPostback = True
        > ' Assuming you're using IIS 5 or later, you can use
        > Server.Execute to call another script.
        > ' However, for this example it'll be done in-line in this
        > script.
        > dat = .form("ud") ' you don't indicate just what 'dat' is[/color]
        used[color=blue]
        > for
        > set cn = createobject("A DODB.Connection ")
        > set rs = createobject("A DODB.Recordset" )
        > strSQL = "select count(uur) as totdag from studres" '[/color]
        lcount??[color=blue]
        > cn.Open("provid er=Microsoft.Je t.OLEDB.4.0; Data
        > Source=c:\acces s\test.mdb")
        > with rs
        > .cursortype = adOpenStatic ' 3
        > .locktype = adLockReadOnly ' 1
        > .activeconnecti on = cn
        > .open strSQL
        > .activeconnecti on = nothing
        > ' if you are only reading, always close the connection
        > immediately
        > ' only keep it open if you will be doing more work right
        > then
        > cn.close
        > if .recordcount > 0 then
        > ' no need to assign recordcount unless you will use it
        > more than once
        > totd = CLng(.Fields("t otdag").Value) ' casting[/color]
        numerics[color=blue]
        > is a good idea
        > end if
        > .close
        > end with
        > set rs = nothing
        > set cn = nothing
        > end if
        > end with
        > %>
        > <html>
        > <head>
        > </head>
        > <body>
        > <form <form name="totd" method="post">
        > <input name="ud" type="hidden" value="">
        > <% if 1 = 0 then %>
        > comment: you can use the dropdown's change event as you had
        > to do the assignment and submit, but you and just as easily get
        > its value as .form("thedropd ownsname") from the script's
        > request object
        > <% end if %>
        > </form>
        > <% if IsPostback then %><br>The value of 'totd'[/color]
        is:&nbsp;<%=tot d%><br><%[color=blue]
        > end if %>
        > </body>
        > </html>
        >
        > Alternatively, you could put your processing code in a Function within the
        > script, or in another file containing common routines you use and use an
        > #include directive in pages you want it.
        >
        > Alan
        >
        >[/color]


        Comment

        • J. Alan Rueckgauer

          #5
          Re: how to go from VB in a page to ASP in another page and come back


          "Andre" <aa@no.it> wrote in message
          news:eZnL45hXEH A.3972@TK2MSFTN GP12.phx.gbl...[color=blue]
          > but if i understand your code, the value from ASP is put outside the SUB.[/color]
          Is[color=blue]
          > it not possible to get that value within the SUB dag_onchange(), because
          > that value must be tested in the SUB and determines the visibility style[/color]
          of[color=blue]
          > another SELECT in the same page etc ...
          > If i get that value outside SUB dag_onchange, how can i make the other
          > select visible?
          >
          > thanks again
          >
          >[/color]
          [snip]

          The way you have described it, "Sub dag_onchange" is client-side event
          script, meaning it is executed in the browser, not the server. The server
          has absolutely no knowledge of events that occur in the browser. It only
          knows something is going on when the form is submitted back to the server.
          The server can only leave results for the client through <%=...%> script
          tags that are replaced when the server prepares the page, not after it is
          received in the browser. For instance, if you have this in a client event
          script block:

          If dag.value = "<%=AServerSide Variable%>" then
          'do something
          End If

          the result you'll see if you view the source in the browser would be
          something like:

          If dag.value = "This is what the server left." then

          You can't do a direct comparison such as:

          If dag.value = AServerSideVari able then

          In other words, in the client script you are not comparing your variable
          against a server variable, you are comparing the client variable to a
          literal representing an actual *value* left by the server. From the client
          perspective, it is the same as if you typed the value in yourself.

          Try this sample to get an idea of what I mean (the code's formatted a bit
          awkwardly, but that's to avoid line-wrap problems):

          **** begin sample file "testforandre.a sp" ****

          <% option explicit %>
          <%
          dim IsPostback, strMethod, TextOptionPickV al
          dim TextForOptionPi ck, TextForTextbox
          dim MagicWord, UsedMagicWord

          IsPostback = false
          strMethod = ""
          TextForOptionPi ck = ""
          TextForTextbox = ""
          MagicWord = "boo"
          UsedMagicWord = false

          with request
          strMethod = lcase(.serverva riables("REQUES T_METHOD"))
          if strMethod = "post" then
          IsPostback = true
          TextOptionPickV al = .form("D1")
          select case TextOptionPickV al
          case ""
          TextForOptionPi ck = "Nothing"
          case "1"
          TextForOptionPi ck = "the first item"
          case "2"
          TextForOptionPi ck = "the second item"
          case "3"
          TextForOptionPi ck = "the third item"
          end select
          TextForTextbox = trim(.Form("T1" ))
          If TextForTextbox = "" then
          TextForTextbox = "<b>You didn't type anything.</b>"
          Else
          if instr(TextForTe xtbox, MagicWord) > 0 then
          UsedMagicWord = true
          end if
          TextForTextbox = "You typed: " & _
          "<font color=""red"">< b>" & _
          TextForTextbox & "</b></font>"
          end if
          end if
          end with
          %>
          <html>
          <head>
          <title>Test Posting Script for Andre</title>
          </head>
          <body>
          <form method="POST">
          <p>Hello, Andre. Postback is <%=IsPostback%> .</p>

          <% if IsPostBack then 'form was submitted %>
          <p>You picked <%=TextForOptio nPick%>
          from the list (<%=TextOptionP ickVal%>)</p>
          <p><%=TextForTe xtbox%></p>
          <p><% if UsedMagicWord then %>
          You typed the magic word!
          <% else %>
          You did not type the magic word.
          <% end if %></p>
          <p>Is it making more sense now?</p>
          <p>(use 'back' to try it again)</p>

          <% else 'form wasn't submitted %>

          <p>Fill out the form and click submit.</p>
          <p>Pick one of these:
          <select size="1" name="D1">
          <option value="">(Pleas e pick)</option>
          <option value="1">Optio n 1</option>
          <option value="2">Optio n 2</option>
          <option value="3">A Third Option</option>
          </select></p>
          <p>Type something here:
          <input type="text" name="T1" size="20"></p>
          <% if not UsedMagicWord then %>
          (Try typing "<%=MagicWord%> " anywhere in the
          textbox and see what happens.)
          <% end if %>
          <p>
          <input type="submit" value="Submit" name="B1"></p>

          <% end if %>
          </form>
          </body>
          </html>

          *** end of "testforandre.a sp" ****

          Run the page. In the browser, view | source both before and after you
          submit it and compare it to the script code. Try it a number of times with
          different inputs. You'll be able to see where the server variables were
          inserted, and how the logic in the client script determined what to display
          based on what you entered or whether you had submitted the form.

          While I did not show you actual interaction between client event script and
          the server, the principles are essentially the same: The server can work
          with values you submit via form input controls, and you get back literal
          values from the server that you can test in the client's script. However,
          you can't directly mix the two.

          I hope this clears it up a bit more.

          Alan


          Comment

          Working...