Home > ASP.NET > Access HTML Controls From code behind

Access HTML Controls From code behind

This week i found an interesting logic to get the value of all HTML controls in a form from code behind..
Suitation
I am working on a dynamic form and the form contains no of input controls with unique name..
On the load evnt of page using innerhtml i build the form on the div inputs

Now on submi button click event of this form i need all values of input controls(NOte: There is no runat=”server” attribute with controls)

string value = Request.Form["mycontrol"];
 

this code returns the value of an input control with id [“mycontrol”] and

string[] controls = Request.Form.AllKeys;

this code returns the id of all input controls in the form

Logic here is

loop through all controols and get their values
protected void btnupdate_Click(object sender, EventArgs e)
{

string[] controls = Request.Form.AllKeys;
for (int i = 0; i < controls.Length; i++)
{
string value = Request.Form[controls[i]]; //contains the value of  input control.Before doing this check the controls[i] contains any portion of control name like this if (controls[i].Contains(“tblindustry”)
}

}

Advertisements
Categories: ASP.NET
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: