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

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: J. Alan Rueckgauer (void_at_dev.nul)
Date: 06/30/04


Date: Wed, 30 Jun 2004 09:10:08 -0400


"Andre" <aa@no.it> wrote in message
news:eZnL45hXEHA.3972@TK2MSFTNGP12.phx.gbl...
> 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
>
>
[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 = "<%=AServerSideVariable%>" 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 = AServerSideVariable 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.asp" ****

<% option explicit %>
<%
  dim IsPostback, strMethod, TextOptionPickVal
  dim TextForOptionPick, TextForTextbox
  dim MagicWord, UsedMagicWord

  IsPostback = false
  strMethod = ""
  TextForOptionPick = ""
  TextForTextbox = ""
  MagicWord = "boo"
  UsedMagicWord = false

  with request
    strMethod = lcase(.servervariables("REQUEST_METHOD"))
    if strMethod = "post" then
      IsPostback = true
        TextOptionPickVal = .form("D1")
        select case TextOptionPickVal
          case ""
            TextForOptionPick = "Nothing"
          case "1"
            TextForOptionPick = "the first item"
          case "2"
            TextForOptionPick = "the second item"
          case "3"
            TextForOptionPick = "the third item"
        end select
        TextForTextbox = trim(.Form("T1"))
        If TextForTextbox = "" then
          TextForTextbox = "<b>You didn't type anything.</b>"
        Else
          if instr(TextForTextbox, 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 <%=TextForOptionPick%>
 from the list (<%=TextOptionPickVal%>)</p>
 <p><%=TextForTextbox%></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="">(Please pick)</option>
 <option value="1">Option 1</option>
 <option value="2">Option 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.asp" ****

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



Relevant Pages

  • Re: Banana Republic (was Re: OpenVMS Book Wins award)
    ... overtaken by the more prosaic aspects of supporting WASD. ... for example), that it is better economy, if a client breaks the ... to allow a script to run to completion rather than try and ... The server just throws away ...
    (comp.os.vms)
  • Re: Regarding a selection for mobile code/scripting language
    ... Client Side scripting, so the server can send script commands to the client. ... I decided they should be scripted and mobile code. ...
    (Vuln-Dev)
  • Re: HTTPSConnection script fails, but only on some servers (long)
    ... (HTTP/CONNECT + switch to HTTPS) ... wget and my python script. ... >>The python script works with server A, ... the problem seems to depend on both the client ...
    (comp.lang.python)
  • Chat client/server print failed
    ... This is a chat client wrote in perl Gtk2. ... is the print statement in the send_msg_all sub. ... leave the server running for testing purposes. ... # just read means there is a complete request waiting ...
    (comp.lang.perl.misc)
  • Re: secure transfers and authentication
    ... Thanks james that looks to be a really handy guide on the whole thing. ... On a side note does anyone know why i have problems posting to the list using the reply function in my mail client? ... From the server ssh to your clients and save the rsa keys ... You could create a script like this: ...
    (Security-Basics)