asp

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • msnews.microsoft.com

    asp

    Hello,

    I have two asp pages (A and B) to be run on the same server and from the
    same client.


    1. In the page A, a checkbox value (checked or not checked) can be
    recognised in the following code :

    If Request.form("C heckBoxName") then ....

    However, in the page B, the same code raises a "type mismatch" error, and it
    has to be modified as follows for the codes to run :

    If Request.form("C heckBoxName") <> "" then ....


    2. In the page A, even if a recordset does not exist as a result of a
    query, it is ignored and the codes can run without error. However, in the
    page B, non-existing recordsets raise an "item cannot be found" error.

    I tried to find out the differences of these two asp pages, but I am so far
    not able to. Does anybody has an idea ?

    Thank you very much,

    Kiyomi




  • Evertjan.

    #2
    Re: asp

    msnews.microsof t.com wrote on 09 jun 2004 in
    microsoft.publi c.inetserver.as p.general:
    [color=blue]
    > I have two asp pages (A and B) to be run on the same server and from
    > the same client.
    >
    >
    > 1. In the page A, a checkbox value (checked or not checked) can be
    > recognised in the following code :
    >
    > If Request.form("C heckBoxName") then ....
    >
    > However, in the page B, the same code raises a "type mismatch" error,
    > and it has to be modified as follows for the codes to run :
    >
    > If Request.form("C heckBoxName") <> "" then ....[/color]

    If Request.form("C heckBoxName") then ....

    Request.form() always returns a string!

    if the string content of CheckBoxName is not litterally true, false or an
    empty string an error will be shown.

    Change it to:

    If lcase(Request.f orm("CheckBoxNa me"))="true" then ....

    or even better: control your form input.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • CJM

      #3
      Re: asp

      It would be easier if your posted comparable code snippets for each page...

      CJM

      "msnews.microso ft.com" <k.kanaoka@unes co.org> wrote in message
      news:%23AYVNNfT EHA.1172@TK2MSF TNGP11.phx.gbl. ..[color=blue]
      > Hello,
      >
      > I have two asp pages (A and B) to be run on the same server and from the
      > same client.
      >
      >
      > 1. In the page A, a checkbox value (checked or not checked) can be
      > recognised in the following code :
      >
      > If Request.form("C heckBoxName") then ....
      >
      > However, in the page B, the same code raises a "type mismatch" error, and[/color]
      it[color=blue]
      > has to be modified as follows for the codes to run :
      >
      > If Request.form("C heckBoxName") <> "" then ....
      >
      >
      > 2. In the page A, even if a recordset does not exist as a result of a
      > query, it is ignored and the codes can run without error. However, in the
      > page B, non-existing recordsets raise an "item cannot be found" error.
      >
      > I tried to find out the differences of these two asp pages, but I am so[/color]
      far[color=blue]
      > not able to. Does anybody has an idea ?
      >
      > Thank you very much,
      >
      > Kiyomi
      >
      >
      >
      >[/color]


      Comment

      • CJM

        #4
        Re: asp


        "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
        news:Xns950368B F6672Aeejj99@19 4.109.133.29...[color=blue]
        >
        > If Request.form("C heckBoxName") then ....
        >
        > Request.form() always returns a string!
        >
        > if the string content of CheckBoxName is not litterally true, false or an
        > empty string an error will be shown.
        >
        > Change it to:
        >
        > If lcase(Request.f orm("CheckBoxNa me"))="true" then ....
        >
        > or even better: control your form input.[/color]

        I think that this is correct solution:

        If Request.form("C heckBoxName")=" on" then ....

        Chris



        Comment

        • CJM

          #5
          Re: asp

          Or alternatively,

          If Len(Request.for m("CheckBoxName ")) Then ...


          Comment

          • Dave Anderson

            #6
            Re: asp

            msnews.microsof t.com wrote:[color=blue]
            >
            > ...If Request.form("C heckBoxName") then ....
            >
            > However, in the page B, the same code raises a "type mismatch"
            > error, and it has to be modified as follows for the codes to run :
            >
            > If Request.form("C heckBoxName") <> "" then ....[/color]

            All of the other replies seem to be treating Request.form("C heckBoxName") as
            if it is a string, when it is, in fact, an object with properties. I suggest
            that you simply examine the appropriate property rather than depend upon
            implicit conversion of the default property of an object that may or may not
            exist.

            In other words, this does exactly what you want; as a bonus, its language
            encapsulates your logic much more closely than string comparison (I'll show
            why this is important in a moment):

            If Request.Form("C heckBoxName").C ount > 0 Then ...



            According to the HTML spec, a checked (or "on") checkbox is a successful
            control, and will generate a name-value pair:


            So what happens if you do something silly like this**?

            <INPUT NAME="CheckBoxN ame" TYPE="checkbox" VALUE="">

            If you code it this way and the user checks the control, he has selected it,
            and any server-side decisions based on that control state should reflect the
            user's choice. But only one of these treats it correctly:

            If Request.Form("C heckBoxName") Then ...
            If Request.Form("C heckBoxName") <> "" Then ...
            If Request.Form("C heckBoxName").I tem Then ...
            If Request.Form("C heckBoxName").I tem <> "" Then ...
            If Request.Form("C heckBoxName").C ount > 0 Then ...

            Care to guess which one?



            **Since it does not have a current value, the W3C says the browser is not
            *required* to treat it as a successful control. By my observation, some do
            (IE6 and Mozilla), while others do not (Opera).
            --
            Dave Anderson

            Unsolicited commercial email will be read at a cost of $500 per message. Use
            of this email address implies consent to these terms. Please do not contact
            me directly or ask me to contact you directly for assistance. If your
            question is worth asking, it's worth posting.


            Comment

            Working...