Click here to Skip to main content
15,886,834 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
invisible the Access HTML controls in C# without runat=server in ASP.NET


XML
<p style="border-bottom: solid 1px; padding: 6px" name="p1">
                  <span>
                      <input id="allSchools"  onclick="ResetCheckboxes();" type="checkbox" />&nbsp;<b>Select
                          All Schools</b></span>
              </p>



Help me!

Thanks
kamalakar
Posted
Comments
Sergey Alexandrovich Kryukov 15-Oct-12 1:41am    
Why? What are your trying to achieve?
--SA
Zoltán Zörgő 15-Oct-12 1:47am    
Access from where? From your embedded code? From code-behind? From javascript?
Sandip.Nascar 15-Oct-12 1:49am    
HTML Control without runat="server" means, it can be accessed only in client side. So, you cannot access a html control in code behind(server) if you don't use runat="server"

One work around could be trying with cookies. Using JS, add the value in cookies and in code behind access the cookie.
n.podbielski 15-Oct-12 4:01am    
Why do something like this. For this is runat property for.
Ambesha 15-Oct-12 8:51am    
In what valid scenario you would like to use the same ??

You cant access from code file ,you have to access from Javascript only by document.getelementbyid or jquery.
 
Share this answer
 
you can use Page the below code

String grp = Request.Form["txtGroupName"].ToString();

in HTML for input tag, you have name tag. That name is used in above code (txtGroupName)
 
Share this answer
 
HTML
<p style="border-bottom: solid 1px; padding: 6px" name="p1">
   <span>
       <input id="chkAllSchools" name="chkAllSchools"  onclick="ResetCheckboxes();" type="checkbox" />
       <b>Select All Schools</b>
   </span>
</p>


To Acces "allSchools" checkbox (don't forget to set name attribute)

1. For method="get" of form, use C# statement
C#
var result = Request.QueryString["chkAllSchools"];

2. For method="post" of form, use C# statement
C#
var result = Request.Form["chkAllSchools"];

If checkbox is checked C# will give you string "on" (or value attribute if set for checkbox in our case not set), and if checkbox is not checked on form you'll get null in result.
 
Share this answer
 
HtmlControl ctrl = (HtmlControl)this.FindControl("id");
 
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