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.Co unt
'brochure names are prefixed with a b to identify them from the forms
collection
if left(Request.Fo rm.Key(x),1)= "b" then
'check if order count is > 0, if so add it to the orderdetail table
if Request.Form.It em(x) > 0 then
mysql = "INSERT INTO tblOrderDetail (OrderID, BrochureID,
Quanity) VALUES ('" & intOrderID & "','" & right(Request.F orm.Key
(x), len(Request.For m.Key(x))-1) & "','" & Request.Form.It em(x) & "')"
'Response.Write (mysql & "<br>")
ConnOrders.Exec ute mysql
end if
End if
'Response.Write Request.Form.Ke y(x) & " = "
'Response.Write Request.Form.It em(x) & "<br>"
Next
Greg 5 1234
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.C ontrol In Me.Controls
If TypeOf ctrl Is System.Web.UI.W ebControls.Text Box 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
Also, to check for "b" at the beginning of the control's ID, you should
use:
If ctrl.ClientID.S tartsWith("b") Then
...
End If
(Do this after you check the type of ctrl).
Luke
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*******@gmai l.com> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.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.C ontrol In Me.Controls If TypeOf ctrl Is System.Web.UI.W ebControls.Text Box 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
these pages will reside on a Microsoft 2003 server with IIS 6.0
"greg" <an******@micro soft.com> wrote in message
news:Oj******** ******@TK2MSFTN GP12.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*******@gmai l.com> wrote in message news:11******** *************@g 44g2000cwa.goog legroups.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.C ontrol In Me.Controls If TypeOf ctrl Is System.Web.UI.W ebControls.Text Box 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
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.publi c.inetserver.as p.general
Luke This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 I am working on:
http://www3.telus.net/thothworks/LinLeastSqPoly4.html).
I provide a form for a user to enter up to twenty (M = 20) data pairs.
The user need not enter data for all twenty pairs, but
the user must indicate that data is present by...
|
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 = CurrentDb
|
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
|
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 this error:
System.InvalidOperationException: Collection was modified; enumeration
operation may not execute. at
|
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 double click on the topic, the page won't
open.
Right now I'm trying to loop through each document until the document name
equals what I'm looking for. What is the syntax for referencing a specific
document without having to loop through all the...
| |
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
If TypeOf ctrl Is CheckBox Then
'do something here.....
|
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
Example 1 from Allen Browne MVP Access
To use a Multiselect list box for criteria for a report,
you need to loop through its ItemsSelected collection to
create a string that can act as the WhereCondition for
your report.
|
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 favorite Ice Cream flavor is a required field.'+
'\nPlease try again.'
|
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 1 and question2 is selected this code is working fine. But if None of answer of either question selected, it is not iterating through outer loop. Please help me to point out the error.
<html>
<head>
<style type="text/css">
body...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |