clientid:怎么获取控件id的名字,用ClientID这样得到id名字
2008-12-25 16:13
323 查看
<script runat="server">
private string _classcolor1 = "id1";
private string _classcolor2 = "id2";
private string _classcolor3 = "id3";
private string _classcolor4 = "id4";
private string _classcolor5 = "id5";
private string _classcolor6 = "id6";
private string _classcolor7 = "id7";
public string classcolor1
{
get
{
return this._classcolor1;
}
set
{
this._classcolor1 = value;
}
}
public string classcolor2
{
get
{
return this._classcolor2;
}
set
{
this._classcolor2 = value;
}
}
public string classcolor3
{
get
{
return this._classcolor3;
}
set
{
this._classcolor3 = value;
}
}
public string classcolor4
{
get
{
return this._classcolor4;
}
set
{
this._classcolor4 = value;
}
}
public string classcolor5
{
get
{
return this._classcolor5;
}
set
{
this._classcolor5 = value;
}
}
public string classcolor6
{
get
{
return this._classcolor6;
}
set
{
this._classcolor6 = value;
}
}
public string classcolor7
{
get
{
return this._classcolor7;
}
set
{
this._classcolor7 = value;
}
}
</script>
<body>
<div class="Navmenu">
<ul>
<li id="<%=classcolor1 %>"><a href="/index.aspx" target="_parent"><span>
<asp:Literal ID="Label1" runat="server" EnableViewState="false" Text="首 页"></asp:Literal></span></a></li>
<li id="<%=classcolor2 %>"><a href="/Info/CompanyIntroduce.aspx" target="_parent"><span>
<asp:Literal ID="Label2" runat="server" EnableViewState="false" Text="企业介绍"></asp:Literal></span></a></li>
<li id="<%=classcolor3 %>"><a href="/Info/NewsCenter.aspx" target="_parent"><span>
<asp:Literal ID="Label3" runat="server" EnableViewState="false" Text="新闻中心"></asp:Literal></span></a></li>
<li id="<%=classcolor4 %>"><a href="/Product/Default.aspx" target="_parent"><span>
<asp:Literal ID="Label4" runat="server" EnableViewState="false" Text="商品展示"></asp:Literal></span></a></li>
<li id="<%=classcolor5 %>"><a href="/Down/DownCenter.aspx" target="_parent"><span>
<asp:Literal ID="Label5" runat="server" EnableViewState="false" Text="下载中心"></asp:Literal></span></a></li>
<li id="<%=classcolor6 %>"><a href="/Blog/Sitepage/sitespace.aspx" target="_parent">
<span>
<asp:Literal ID="Label6" runat="server" EnableViewState="false" Text="博客"></asp:Literal></span></a></li>
<li id="<%=classcolor7 %>"><a href="/BBS/cebbs/" target="_parent"><span>
<asp:Literal ID="Label7" runat="server" EnableViewState="false" Text="论坛"></asp:Literal></span></a></li></ul>
</div>
</body>
为什么id的名字要用属性的写法是因为在程序编译后id的名字会变,用属性命名字就不会发生变化,前面不会多出其他的字符串。
我之前也曾经写过id名字会变的原因是因为system.web.ui.usecontrol的原因。加了模板会出现这样的问题
要想得到变化了的控件id的名字,可以<%txtName.ClientID%>得到控件id ,还有一种就是我上面写的代码就是用属性给控件命名就可以了。但是属性命名有点麻烦。
private string _classcolor1 = "id1";
private string _classcolor2 = "id2";
private string _classcolor3 = "id3";
private string _classcolor4 = "id4";
private string _classcolor5 = "id5";
private string _classcolor6 = "id6";
private string _classcolor7 = "id7";
public string classcolor1
{
get
{
return this._classcolor1;
}
set
{
this._classcolor1 = value;
}
}
public string classcolor2
{
get
{
return this._classcolor2;
}
set
{
this._classcolor2 = value;
}
}
public string classcolor3
{
get
{
return this._classcolor3;
}
set
{
this._classcolor3 = value;
}
}
public string classcolor4
{
get
{
return this._classcolor4;
}
set
{
this._classcolor4 = value;
}
}
public string classcolor5
{
get
{
return this._classcolor5;
}
set
{
this._classcolor5 = value;
}
}
public string classcolor6
{
get
{
return this._classcolor6;
}
set
{
this._classcolor6 = value;
}
}
public string classcolor7
{
get
{
return this._classcolor7;
}
set
{
this._classcolor7 = value;
}
}
</script>
<body>
<div class="Navmenu">
<ul>
<li id="<%=classcolor1 %>"><a href="/index.aspx" target="_parent"><span>
<asp:Literal ID="Label1" runat="server" EnableViewState="false" Text="首 页"></asp:Literal></span></a></li>
<li id="<%=classcolor2 %>"><a href="/Info/CompanyIntroduce.aspx" target="_parent"><span>
<asp:Literal ID="Label2" runat="server" EnableViewState="false" Text="企业介绍"></asp:Literal></span></a></li>
<li id="<%=classcolor3 %>"><a href="/Info/NewsCenter.aspx" target="_parent"><span>
<asp:Literal ID="Label3" runat="server" EnableViewState="false" Text="新闻中心"></asp:Literal></span></a></li>
<li id="<%=classcolor4 %>"><a href="/Product/Default.aspx" target="_parent"><span>
<asp:Literal ID="Label4" runat="server" EnableViewState="false" Text="商品展示"></asp:Literal></span></a></li>
<li id="<%=classcolor5 %>"><a href="/Down/DownCenter.aspx" target="_parent"><span>
<asp:Literal ID="Label5" runat="server" EnableViewState="false" Text="下载中心"></asp:Literal></span></a></li>
<li id="<%=classcolor6 %>"><a href="/Blog/Sitepage/sitespace.aspx" target="_parent">
<span>
<asp:Literal ID="Label6" runat="server" EnableViewState="false" Text="博客"></asp:Literal></span></a></li>
<li id="<%=classcolor7 %>"><a href="/BBS/cebbs/" target="_parent"><span>
<asp:Literal ID="Label7" runat="server" EnableViewState="false" Text="论坛"></asp:Literal></span></a></li></ul>
</div>
</body>
为什么id的名字要用属性的写法是因为在程序编译后id的名字会变,用属性命名字就不会发生变化,前面不会多出其他的字符串。
我之前也曾经写过id名字会变的原因是因为system.web.ui.usecontrol的原因。加了模板会出现这样的问题
要想得到变化了的控件id的名字,可以<%txtName.ClientID%>得到控件id ,还有一种就是我上面写的代码就是用属性给控件命名就可以了。但是属性命名有点麻烦。
相关文章推荐
- ClientID 获取服务端控件,客户端id的方法
- jquery 怎么获取服务器控件ID
- 搞懂了MSN协议中的client id是怎么得到的
- c#的winform,怎么根据控件的名字获取控件属性!
- Android 通过resource名称或者layout中定义的id name 去获取R.java中id,得到控件
- html 控件 怎么获取id
- ASP.Net中使用ClientID获取服务端控件ID
- Atitit.获取swing ui 按钮控件的id 与名字 与JPDA 调试体系
- jquery获取的id含有特殊符号怎么办
- 从前端获取ID时,出现前缀怎么办
- C# Timer 控件 c#怎么获取timer剩余时间 倒计时数秒 如何获取 Interval 设置完的等待时间
- C# 实现读取本地某文件夹中的html文件,然后通过正则表达式获取input控件中的id值
- c++ builder2010 indy控件idhttp, post页面获取数据(要注意编码的问题,双方都使用UTF-8最好)
- 根据控件Id得到控件并对该控件进行操作
- .NET中获取服务器端控件的ID进行客户端编程
- Flex编程注意之直接获取某个组件的对象(this[]用法)通过id获取控件
- 如何在fragment中获取自定义view的控件id
- 【ASP.NET】js动态生成的控件,在后台获取不到怎么办?
- 如图这样的控件 怎么实现? asp.net B/S
- 原来可以这样得到控件的html文本