There is some requirement where we need to create HTML controls dynamically in c# with the string format using StringBuilder and then write the string to a page. And whenever some event raised like button click event, on server side code, we need to retrieve the values of those HTML controls. Please follow the solution below to get the values of the HTML controls which doesn't have runat="server" attribute defined.
Example:HTML declaration:
<input type="text" name="txtName" />
C# Code:
string strValue = Page.Request.Form["name of the control"].ToString();
Note:
To get the values in server side code of HTML control, we need to follow below points.
Example:HTML declaration:
<input type="text" name="txtName" />
C# Code:
string strValue = Page.Request.Form["name of the control"].ToString();
Note:
To get the values in server side code of HTML control, we need to follow below points.
- The form method should be of type POST.
- The tag should have an attribute called NAME. Because it is used as key in form[].
No comments:
Post a Comment