Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to access HTML control to asp.net code file? I want to hide them in page load. But they can't be accessed.
Please help me..Thanks in advance
Posted
Updated 10-May-17 5:03am
v2

add runat="server" in the control.

eg:
<br />
 <a id="somelink" runat="server" href="#"></a><br />
 
Share this answer
 
Comments
LakshmiNarayana Nalluri 9-May-11 5:18am    
i agree with this answer
Ankur\m/ 9-May-11 5:27am    
But I don't!
Ankur\m/ 9-May-11 5:28am    
That's not correct. If you want to have HTML controls on the page, you can have them as well and get their values on the server side using Request Object.
Hemant__Sharma 9-May-11 5:41am    
But it is when the Request has control name. What about first request to the page?
Ankur\m/ 9-May-11 5:55am    
I don't know if there is a way to do that. But why do you need to? All the control's properties can be set on the page and if you need the control's value, that will be only on a postback.
1. Set id and name property in same name.
then
var control1= Request.Form["name_of_control"];

2.Add runat="server" to the controls, and then you can access them from the code-behind almost as if they were <asp:______ xmlns:asp="#unknown"> controls.
 
Share this answer
 
Comments
Ankur\m/ 9-May-11 5:35am    
1. Why var?
2. It's no more an HTML control then.
 
Share this answer
 
Page_Load event
------------
if (Request.Form["Text1"] != null)
{
Response.Write(Request.Form["Text1"].ToString());
}

ASPX PAGE
---------
Form should post method
<input id="Text1" name="Text1" type="text" value="ABCD" style="width:200px;"/>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900