Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2006

Tip: Looking for answers? Try searching our database.

Looping Forms Collection Error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
greg - 17 Feb 2006 17:31 GMT
HI,

I have an asp page that loops through the forms collection gathering data
from input controls that web surfers have entered in.  The problem I have is
when I get to the submit button, I get the follow error "Type mismatch:
'[string: "Send Me the Brochure"]' " "send me the brochure" is the text on
the submit button.  I don't know how to have the loop skip the submit
button.  Any help would be appreciated.

here is the code:

dim x
For x = 1 to Request.Form.Count
   'brochure names are prefixed with a b to identify them from the forms
collection
   if left(Request.Form.Key(x),1)= "b" then
       'check if order count is > 0, if so add it to the orderdetail table
       if Request.Form.Item(x) > 0  then
           mysql = "INSERT INTO tblOrderDetail (OrderID, BrochureID,
Quanity) VALUES ('" & intOrderID & "','" & right(Request.Form.Key
(x), len(Request.Form.Key(x))-1) & "','" & Request.Form.Item(x) & "')"
               'Response.Write(mysql & "<br>")
               ConnOrders.Execute mysql
       end if
    End if

   'Response.Write Request.Form.Key(x) & " = "
   'Response.Write Request.Form.Item(x) & "<br>"
Next

Greg
slagomite - 17 Feb 2006 18:42 GMT
The more natural way to do this in ASP.NET would be to loop through the
Page object's Controls collection.  For example:

Dim strCtrlValue As String

For Each ctrl As System.Web.UI.Control In Me.Controls
   If TypeOf ctrl Is System.Web.UI.WebControls.TextBox Then
       strCtrlValue = CType(ctrl, TextBox).Text
       ' (do your work now using the strCtrlValue variable,
       ' or just use CType(ctrl, TextBox).Text directly)
   End If
Next

(I'm not a 100% on the VB syntax since I use C#...)
This way, you're explicitly checking that the type of the form control
is a TextBox (or whatever type of control(s) you're looking for), and
thus your submit button won't be used.

As a very important aside -- the way you're creating your SQL query
string is *extremely* dangerous.  It can easily be exploited by
hackers.  For example, if a hacker was to type in the following for one
of the form fields:

   ) DELETE tblOrderDetail --

Your entire tblOrderDetail table would be wiped out.  (This is called
"sql injection".)  You should look into using the ADO.NET command
object, and parameterized queries.

HTH
Luke
slagomite - 17 Feb 2006 18:54 GMT
Also, to check for "b" at the beginning of the control's ID, you should
use:

If ctrl.ClientID.StartsWith("b") Then
   ...
End If

(Do this after you check the type of ctrl).

Luke
greg - 17 Feb 2006 19:21 GMT
Luke,

thank you for your reply, I am not familiar with AD0.NET.  Would this be a
lot of work to set up?

Greg

> The more natural way to do this in ASP.NET would be to loop through the
> Page object's Controls collection.  For example:
[quoted text clipped - 27 lines]
> HTH
> Luke
greg - 17 Feb 2006 19:35 GMT
these pages will reside on a Microsoft 2003 server with IIS 6.0

> Luke,
>
[quoted text clipped - 34 lines]
>> HTH
>> Luke
slagomite - 17 Feb 2006 20:37 GMT
Oh...  You're using classic ASP, not ASP.NET?  You're in the wrong
newsgroup...  Sorry, you'll have to disregard (most of) my response.
The SQL injection stuff definitely still applies, though.

Try the ASP newsgroup:
microsoft.public.inetserver.asp.general

Luke

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.