在ASP.NET中访问C#中没有runat = server的HTML控件 [英] Access HTML controls in C# without runat=server in ASP.NET

查看:301
本文介绍了在ASP.NET中访问C#中没有runat = server的HTML控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

隐藏了C#中的Access HTML控件而没有在ASP.NET中使用runat = server





 <   p    样式  =  border-bottom:solid 1px; padding:6px    name   =  p1 >  
< span >
< < span class =code-leadattribute> input id = allSchools onclick = ResetCheckboxes(); 类型 = 复选框 / > & nbsp; < b > 选择
所有学校< / b > < / span >
< / p >







帮助我!



谢谢

kamalakar

解决方案

< blockquote>你无法从代码文件访问,你只能通过document.getelementbyid或jquery从Javascript访问。


你可以使用Page下面的代码



字符串grp = Request.Form [txtGroupName]。ToString();



输入标签的HTML,你有名字标签。该名称用于上面的代码(txtGroupName)


 <   p     style   =   border-bottom:solid 1px; padding:6px    name   =  p1 >  
< span >
< 输入 id = chkAllSchools nam e = chkAllSchools onclick = ResetCheckboxes(); type = 复选框 / >
< b > 选择所有学校< / b >
< / span >
< / p >





要访问allSchools复选框(不要忘记设置名称属性)



1.对于 method =get 表单,使用C#语句

  var  result = Request.QueryString [  chkAllSchools]; 



2.对于 method =post表单,使用C#语句

  var  result = Request .Form [  chkAllSchools]; 



如果选中复选框,C#将为您提供字符串on(如果在我们的情况下未设置复选框,则设置为value属性),如果未在表单上选中复选框,则结果将为null。


invisible the Access HTML controls in C# without runat=server in ASP.NET


<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

解决方案

You cant access from code file ,you have to access from Javascript only by document.getelementbyid or jquery.


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)


<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

var result = Request.QueryString["chkAllSchools"];


2. For method="post" of form, use C# statement

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.


这篇关于在ASP.NET中访问C#中没有runat = server的HTML控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆