3/3/09

How to access HTML Input control value from .aspx page?

Hi all,
If you are accessing a plain HTML form, it HAS to be submitted to the server via a submit button (or via a javascript post). This means that your definuition looks something like this:


<Form action="page.aspx" method="post" >
<input id="customerName" name="customerName" >
<input id="customerPhone" name="customerPhone" >
< type="submit" value="Save" >< /form >

Now, from .aspx page, you should be able to access these controls using this line of code:

string name = Request.Form["customerName"].ToString();

If you are using "GET" method (however, it is not recommended for the sake of security), try using following line:

string name = Request.QueryString["customerName"].ToString();

This, of course will work only if the page is "POSTED", "SUBMITTED" or done via a "POSTBACK", or it was done via a javacript postback.

No comments:

Post a Comment