473,406 Members | 2,705 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,406 software developers and data experts.

Request.Form[""] - catch all and create list

G
Hello,

I have a c# ASPX file, and a Code Behind file.

This file has contents POSTED to it, around 15 form fields. Rather than
manually catch each Request.Form["TextBoxID"] - is there an easy way to
simply create a loop which does the following:

1: Look for ALL posted form fields

2: Create a list of variables, one for each form element - Name the
variables varFormField1, varFormField2, varFormField3 and so on

3: Populate each variable with a form field, TextBox1 populates
varFormField1, TextBox2 populates varFormField2 etc.

Any help appreciated. This is my first .net project and it's a biggy.
Hurting my head :)

G.

Feb 6 '07 #1
3 1959
Hello,
>
I have a c# ASPX file, and a Code Behind file.

This file has contents POSTED to it, around 15 form fields. Rather
than manually catch each Request.Form["TextBoxID"] - is there an easy
way to simply create a loop which does the following:

1: Look for ALL posted form fields

2: Create a list of variables, one for each form element - Name the
variables varFormField1, varFormField2, varFormField3 and so on

3: Populate each variable with a form field, TextBox1 populates
varFormField1, TextBox2 populates varFormField2 etc.

Any help appreciated. This is my first .net project and it's a biggy.
Hurting my head :)

G.
Is that an asp.net form with TextBoxes etc? Then you don't need to work with
Request.Form. The values of the textboxes are updated automatically when
you (or rather the user) submit the form.
Note: if you pre-fill the textboxes, wrap that part in a " if (!IsPostback)
" test,
so you don't overwrite the values that the user entered or changed.

Hans Kesting
Feb 6 '07 #2
G wrote:
Hello,

I have a c# ASPX file, and a Code Behind file.

This file has contents POSTED to it, around 15 form fields. Rather than
manually catch each Request.Form["TextBoxID"] - is there an easy way to
simply create a loop which does the following:

1: Look for ALL posted form fields
That part is easy. Request.Form is a collection that you can loop through.
2: Create a list of variables, one for each form element - Name the
variables varFormField1, varFormField2, varFormField3 and so on
You can't create variables dynamically. You can use a collection if you
want a list of named valued, and copy all the items in Request.Form to
it. It's a bit silly, though, as you already have a collection that
contains the values.

I have seen several attempts to handle form data more or less
automatically. Most attempts ended up in horrible code and/or a security
nightmare.

You should always consider form data as not safe. It's better if you
handle the data that you expect than to handle any data that a user
might send to your page.

--
Göran Andersson
_____
http://www.guffa.com
Feb 6 '07 #3
G
You should always consider form data as not safe. It's better if you
handle the data that you expect than to handle any data that a user might
send to your page.

--
Göran Andersson


Thanks for the tips - I am using session objects, and have individually
referenced and created the sessions.

G.

Feb 7 '07 #4

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

Similar topics

2
by: John Davis | last post by:
I want to know what's the differences between Request.Form("Field Name") and Request.QueryString("Field Name") OR they function exactly the same, which is to return the value of the field?? ...
1
by: Matt | last post by:
If we use GET protocol, we can use either Request("controlname") or Request.QueryString("controlname") to get the data entered by the user. But if we use POST protocol, we MUST use...
32
by: James Curran | last post by:
I'd like to make the following proposal for a new feature for the C# language. I have no connection with the C# team at Microsoft. I'm posting it here to gather input to refine it, in an "open...
9
by: Dan | last post by:
I am trying to use Request.Form("__EVENTTARGET") to get the name of the control that caused a post back. It keeps returning "". I am not really sure why, this happens for all of my controls...
7
by: al | last post by:
Greetings all, I use request.form("textbox1") to get data back to page, dim str as string str = request.form("textbox1").tostring But str is always empty after refresh???? I use asp.net...
1
by: Abe Simpson | last post by:
Hi all, My form file has this attribute: <META http-equiv="Content-Type" content="text/html; charset=utf-8"> The form's action points to an .aspx file where I try to retrieve field values...
8
by: abcd | last post by:
I can get the value on the form at the server side by using Request.form("max") when max field is disabled I dont get value. For GUI and business logic purpose I have disabled some fields with...
7
by: Rich | last post by:
Hi, I was experimenting with some basic sample asp code but can't get it to work correctly: this is bgselector.asp which works OK - you add the name of a basic color like blue, green, yellow...
7
by: sami | last post by:
Hi I am trying to write a facebook application in python - I have been programming simple desktop applications till now and am not really familiar with web apps Pyfacebook is the wrapper for...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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
tracyyun
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...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.