473,398 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Looping Forms Collection Error

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
Feb 17 '06 #1
5 1225
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

Feb 17 '06 #2
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

Feb 17 '06 #3
Luke,

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

Greg

"slagomite" <sl*******@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
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

Feb 17 '06 #4
these pages will reside on a Microsoft 2003 server with IIS 6.0

"greg" <an******@microsoft.com> wrote in message
news:Oj**************@TK2MSFTNGP12.phx.gbl...
Luke,

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

Greg

"slagomite" <sl*******@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
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


Feb 17 '06 #5
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

Feb 17 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: David | last post by:
Hello. I am looking for advice on what is "best practice" regarding looping through a form to check its checkboxes and associated data fields. Here is what I am trying to do (Here is the page...
1
by: Jozef | last post by:
Hello, I'm trying to loop through forms by doing a "For Each" in the Currentdb. I'm doing this like the following; Dim db as dao.database Dim docLoop as document Dim ctrl as control Set db...
16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
3
by: VB Programmer | last post by:
Here's the code: For Each li As ListItem In Me.lstAssignedEmailAddresses.Items If li.Selected = True Then Me.lstAssignedEmailAddresses.Items.Remove(li) End If Next When I remove an item I get...
3
by: Jozef | last post by:
Hi Folks! I'm trying to reference a specific table using the containers collection. I'm trying to use my help file to find out more about how to accomplish this, but for some reason, when I...
7
by: astro | last post by:
I am not farmilar with the object model for webforms. I want to loop through the web form controls - pulling out the checkboxes on the form like the following: For Each ctrl In Me.Controls ...
2
by: pob | last post by:
Whats the difference between using a control or a listbox when looping thru a listbox. In example 1 it dims a listbox and an example 2 it dims a control. Please explain. Thanks in advance ...
3
by: SAM | last post by:
ll a écrit : <script type="text/javascript"> function checkform( f ) // f is the form to check { var txt1 = 'Please make a selection for the Learning Outcome :', txt2 = '\nYour...
3
by: chiku1523 | last post by:
Hi, Please find the following code. In function setAnswers, I am looping with each question. I have inner loop, which is looping for each answers of the questions. If any of the answer for question...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.