LOOP through an ASP form's pages (not ASP.NET - ASP classic)

Discussion in 'ASP General' started by David A. Beck, Apr 12, 2004.

  1. I found a great article and use the techniques to loop through a form and
    get all the controls in ASP.NET "Looping Through Controls in ASP.NET"
    http://www.extremeexperts.com/Net/Articles/LoopingthroughControls.aspx

    I want to do the same thing in a VB COM control for classic ASP. Can anyone
    point me to an article that shows me how to get the control type, etc?

    Dab
    David A. Beck, Apr 12, 2004
    #1
    1. Advertising

  2. Curt,

    In the COM object, using the scripting context, there is no .Items
    collection in the Request Object.

    Dab
    "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
    news:...
    > perhaps
    >
    > for each item in Reqest.Items
    > response.write item & "=" & item.value
    > next
    >
    >
    > --
    > Curt Christianson
    > Owner/Lead Developer, DF-Software
    > www.Darkfalz.com
    >
    >
    > "David A. Beck" <> wrote in message
    > news:...
    > > I found a great article and use the techniques to loop through a form

    and
    > > get all the controls in ASP.NET "Looping Through Controls in ASP.NET"
    > > http://www.extremeexperts.com/Net/Articles/LoopingthroughControls.aspx
    > >
    > > I want to do the same thing in a VB COM control for classic ASP. Can

    > anyone
    > > point me to an article that shows me how to get the control type, etc?
    > >
    > > Dab
    > >
    > >

    >
    >
    David A. Beck, Apr 12, 2004
    #2
    1. Advertising

  3. David A. Beck

    Scott McNair Guest

    "David A. Beck" <> wrote in
    news::

    > I found a great article and use the techniques to loop through a form
    > and get all the controls in ASP.NET "Looping Through Controls in
    > ASP.NET"
    > http://www.extremeexperts.com/Net/Articles/LoopingthroughControls.aspx
    >
    > I want to do the same thing in a VB COM control for classic ASP. Can
    > anyone point me to an article that shows me how to get the control
    > type, etc?


    If you're calling the form thru <form method=post>, it would be

    For Each Item In Request.Form
    Response.Write Item & ": " & Request(Item) & "<br>"
    Next

    If it's just a generic <form> object,

    For Each Item In Request.QueryString
    Response.Write Item & ": " & Request(Item) & "<br>"
    Next
    Scott McNair, Apr 12, 2004
    #3
  4. David A. Beck

    Evertjan. Guest

    Scott McNair wrote on 12 apr 2004 in
    microsoft.public.inetserver.asp.general:
    > For Each Item In Request.Form
    > Response.Write Item & ": " & Request(Item) & "<br>"
    > Next


    This will not be correct if there is also a querystring

    Use:

    For Each Item In Request.Form
    Response.Write Item & ": " & Request.Form(Item) & "<br>"
    Next


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Apr 12, 2004
    #4
  5. Scott:

    Could you send a small page with this code in it, because I'm not getting
    any joy using it in mime. Thanks.

    Dab
    "Scott McNair" <> wrote in message
    news:Xns94C9967EEBEACsfmco@207.46.248.16...
    > "David A. Beck" <> wrote in
    > news::
    >
    > > I found a great article and use the techniques to loop through a form
    > > and get all the controls in ASP.NET "Looping Through Controls in
    > > ASP.NET"
    > > http://www.extremeexperts.com/Net/Articles/LoopingthroughControls.aspx
    > >
    > > I want to do the same thing in a VB COM control for classic ASP. Can
    > > anyone point me to an article that shows me how to get the control
    > > type, etc?

    >
    > If you're calling the form thru <form method=post>, it would be
    >
    > For Each Item In Request.Form
    > Response.Write Item & ": " & Request(Item) & "<br>"
    > Next
    >
    > If it's just a generic <form> object,
    >
    > For Each Item In Request.QueryString
    > Response.Write Item & ": " & Request(Item) & "<br>"
    > Next
    David A. Beck, Apr 12, 2004
    #5
  6. David A. Beck

    Scott McNair Guest

    "David A. Beck" <> wrote in news:u8XdHsMIEHA.2836
    @TK2MSFTNGP11.phx.gbl:

    > Scott:
    >
    > Could you send a small page with this code in it, because I'm not getting
    > any joy using it in mime. Thanks.
    >
    > Dab


    On it's way!

    -Scott
    Scott McNair, Apr 12, 2004
    #6
  7. David A. Beck

    [MSFT] Guest

    Hi David,

    In ScriptingContext, IRequest interface also have FORM collection. You may
    take a look at following MSDN articles:

    Request.Form Collection
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/
    ref_vbom_reqocf.asp

    Request Object
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/
    ref_vbom_reqo.asp?frame=true

    IScriptingContext::get_Request
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/
    ref_biobj_cppiscget_rqst.asp

    IScriptingContext C++ Interface
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/
    ref_biobj_cppisc.asp

    Accessing ASP Built-In Objects from Components
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/
    accessingaspbuiltinobjectsfromcomponents.asp

    In the post you sent in asp.components, I may misunderstand your
    description. I think above information should be what you are looking for.
    Hope them help.

    Luke
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    [MSFT], Apr 13, 2004
    #7
  8. David A. Beck

    Scott McNair Guest

    Scott McNair <> wrote in
    news:Xns94C9967EEBEACsfmco@207.46.248.16:

    > If you're calling the form thru <form method=post>, it would be
    >
    > For Each Item In Request.Form
    > Response.Write Item & ": " & Request(Item) & "<br>"
    > Next
    >
    > If it's just a generic <form> object,
    >
    > For Each Item In Request.QueryString
    > Response.Write Item & ": " & Request(Item) & "<br>"
    > Next


    Just as a side note, I've found this technique very useful for
    populating a table on a database - as long as the field names in the
    table are the same as the form object names, it's as easy as:

    [set up your connection, recordset, etc]
    RS.AddNew
    For Each Item In Request.Form
    RS(Item) = Request.Form(Item)
    Next
    RS.Update

    I find it's a good way to populate a table with a kajillion different
    fields from a table with a kajillion different fields, in essentially 3
    lines of code.
    Scott McNair, Apr 13, 2004
    #8
  9. Scott McNair wrote:
    > Scott McNair <> wrote in
    > news:Xns94C9967EEBEACsfmco@207.46.248.16:
    >
    > Just as a side note, I've found this technique very useful for
    > populating a table on a database - as long as the field names in the
    > table are the same as the form object names,


    And the datatypes cooperate ....

    > it's as easy as:
    > [set up your connection, recordset, etc]
    > RS.AddNew
    > For Each Item In Request.Form
    > RS(Item) = Request.Form(Item)
    > Next
    > RS.Update
    >
    > I find it's a good way to populate a table with a kajillion different
    > fields from a table with a kajillion different fields, in essentially
    > 3 lines of code.


    It's great for the coder - not so good for the application performance and
    scalability. Cursors should not be used for data maintenance. How about
    this:

    sSQLi = "INSERT INTO table ("
    sSQLv = " VALUES("
    for each Item In Request.Form
    sSQLi = sSQLi & Item & ","
    'you will need logic here to handle various datatypes
    Select Case datatype
    Case "Text"
    sSQLv= sSQLv & "'" & Replace(Request.Form(Item),"'","''") & "',"
    Case "Number"
    sSQLv= sSQLv & Replace(Request.Form(Item),"'","''") & ","
    Case "Date"
    sSQLv= sSQLv & "#" & Replace(Request.Form(Item),"'","''") & "#,"
    Next
    'get rid of the trailing commas
    sSQLi = Left(sSQLi,len(sSQLi) - 1) & ")"
    sSQLv = Left(sSQLv,len(sSQLv)-1) & ")"
    sSQL = sSQLi & sSQLv
    Response.write sSQL
    conn.Execute ,,129

    Now you've had to write a little more code, but, now you've handled all the
    chores that ADO needs to do behind the scenes anyways when updating a
    recordset. Pluse you've eliminated the need to open an expensive updatable
    cursor.

    Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Apr 13, 2004
    #9
  10. David A. Beck

    Scott McNair Guest

    "Bob Barrows [MVP]" <> wrote in
    news::

    > Now you've had to write a little more code, but, now you've handled
    > all the chores that ADO needs to do behind the scenes anyways when
    > updating a recordset. Pluse you've eliminated the need to open an
    > expensive updatable cursor.


    Good call.
    Scott McNair, Apr 13, 2004
    #10
  11. David A. Beck

    Scott McNair Guest

    "Bob Barrows [MVP]" <> wrote in
    news::


    [snip]
    > 'you will need logic here to handle various datatypes


    One way would be to name your form objects so that the first three
    letters describe the data type... e.g. txtName, numAge, datRegistered,
    then do

    Select Case Left(Request.Form(Item),3)
    Case "txt"
    sSQLv = sSQLv & "'" & Right(Request.Form(Item),Len(Request.Form
    (Item))-3) &"',"
    Case "num"
    [etc]
    Case "dat"
    [etc]
    End Select
    Scott McNair, Apr 13, 2004
    #11
    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. Raterus
    Replies:
    4
    Views:
    415
    John Saunders
    Jun 17, 2004
  2. Guest
    Replies:
    1
    Views:
    862
    Kevin Spencer
    May 19, 2005
  3. Replies:
    0
    Views:
    856
  4. bregent
    Replies:
    10
    Views:
    513
    bregent
    Feb 13, 2006
  5. Isaac Won
    Replies:
    9
    Views:
    369
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page