Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping through server-side form fields

Status
Not open for further replies.

theomen

Programmer
Jun 2, 2004
158
GB
Hi All,

I'm hoping someone can help with this as its beginning to wind me up.

Is there a way in asp.net to loop through the fields in a server-side form (ie. with runat="server"), the same way that you can use "for each item in request.form()" for client-side forms?

I want to create a login form that pops up when a users session times out and they attempt to submit a form, I want each field within the users form to be copied to the login form, so when they log back in it can keep hold of the data instead of them having to type it all in again.

I've tried googling the query but I've had no success yet. I've found a way to get each of the id's, but not the values of the fields.

I've also just tried putting a client-side form in and using the "for each item in request.form()", but all it seems to send through is "__VIEWSTATE".
 
>>the same way that you can use "for each item in request.form()" for client-side forms?


request.form will work both for server as well as normal HTML controls. why not use it???

Known is handfull, Unknown is worldfull
 
Hi vbkris,

When I tried to use it, it just returned "__VIEWSTATE".

I managed to get it working (kind of) in the end using previouspage.findcontrol. However, using this method, I still need to know what controls are on a page. What I'm having to do is send through with each form a hidden field containing the form name / description (ie. PersonalDetails). In the code for the login page, I first use "previouspage.findcontrol("FormName")", then depending on the name of the form, get the fields that the form contains. Its not ideal as it means I have to remember to put this into every form, but it works.

The reason I said "kind of" above is because when i got in this morning I got an error, because I went direct to the login page rather than through a form, so when it checks for the formname it gives me an error saying "object reference not set to an instance of an object". I'm sure I'll figure a way around this one though.

I'm fairly new to .net, so am still learning :)
 
Aha, its all working fine now.

Thanks vbkris for the reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top