accessing html fields

J

Jessica Weiner

I have an input field defined outside the <form> area. Its a simple html
text input that is used to enter the number of hours.

<input id="HoursField" name="hours" type="text" />

I want to access this field from the server side (c# code). I tried these
two methods to access the field but they dont work. Please help.

String[] tempArray;
tempArray = Request.Form.GetValues("hours");
Response.Write (tempArray[0]);

---

string val = Request.QueryString["hours"].ToString();
Response.Write (val);


Jessica
 
S

Scott M.

All form fields MUST be within the <FORM> element, otherwise their
name/value pair are not posted to the server when the form submits.

Also, if you only have one element named "hours" and it is a textbox, it
will not return an array, it will just return one value.

This code will do it:

String hoursValue;
hoursValue = Request.Form("hours");
Response.Write (hoursValue);

Or, you could define the input like this:

<input id="HoursField" name="hours" type="text" runat="server" />

and your server code would simply be:

String hoursValue;
hoursValue = HoursField.Text;
Response.Write (hoursValue);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top