控件id名字的变了,怎么获取控件id的名字,用ClientID这样得到id名字

  1.     "server">
  2.         private string _classcolor1 = "id1";
  3.         private string _classcolor2 = "id2";
  4.         private string _classcolor3 = "id3";
  5.         private string _classcolor4 = "id4";
  6.         private string _classcolor5 = "id5";
  7.         private string _classcolor6 = "id6";
  8.         private string _classcolor7 = "id7";
  9.         public string classcolor1
  10.         {
  11.             get
  12.             {
  13.                 return this._classcolor1;
  14.             }
  15.             set
  16.             {
  17.                 this._classcolor1 = value;
  18.             }
  19.         }
  20.         public string classcolor2
  21.         {
  22.             get
  23.             {
  24.                 return this._classcolor2;
  25.             }
  26.             set
  27.             {
  28.                 this._classcolor2 = value;
  29.             }
  30.         }
  31.         public string classcolor3
  32.         {
  33.             get
  34.             {
  35.                 return this._classcolor3;
  36.             }
  37.             set
  38.             {
  39.                 this._classcolor3 = value;
  40.             }
  41.         }
  42.         public string classcolor4
  43.         {
  44.             get
  45.             {
  46.                 return this._classcolor4;
  47.             }
  48.             set
  49.             {
  50.                 this._classcolor4 = value;
  51.             }
  52.         }
  53.         public string classcolor5
  54.         {
  55.             get
  56.             {
  57.                 return this._classcolor5;
  58.             }
  59.             set
  60.             {
  61.                 this._classcolor5 = value;
  62.             }
  63.         }
  64.         public string classcolor6
  65.         {
  66.             get
  67.             {
  68.                 return this._classcolor6;
  69.             }
  70.             set
  71.             {
  72.                 this._classcolor6 = value;
  73.             }
  74.         }
  75.         public string classcolor7
  76.         {
  77.             get
  78.             {
  79.                 return this._classcolor7;
  80.             }
  81.             set
  82.             {
  83.                 this._classcolor7 = value;
  84.             }
  85.         }
  86.     
  87. class="Navmenu">
  88.                         
    •                             "<%=classcolor1 %>">"/index.aspx" target="_parent">
    •                                 "Label1" runat="server" EnableViewState="false" Text="首 页">
    •                             "<%=classcolor2 %>">"/Info/CompanyIntroduce.aspx" target="_parent">
    •                                 "Label2" runat="server" EnableViewState="false" Text="企业介绍">
    •                             "<%=classcolor3 %>">"/Info/NewsCenter.aspx" target="_parent">
    •                                 "Label3" runat="server" EnableViewState="false" Text="新闻中心">
    •                             "<%=classcolor4 %>">"/Product/Default.aspx" target="_parent">
    •                                 "Label4" runat="server" EnableViewState="false" Text="商品展示">
    •                             "<%=classcolor5 %>">"/Down/DownCenter.aspx" target="_parent">
    •                                 "Label5" runat="server" EnableViewState="false" Text="下载中心">
    •                             "<%=classcolor6 %>">"/Blog/Sitepage/sitespace.aspx" target="_parent">
    •                                 
    •                                     "Label6" runat="server" EnableViewState="false" Text="博客">
    •                             "<%=classcolor7 %>">"/BBS/cebbs/" target="_parent">
    •                                 "Label7" runat="server" EnableViewState="false" Text="论坛">
  89.                     
  •               
    1. 为什么id的名字要用属性的写法是因为在程序编译后id的名字会变,用属性命名字就不会发生变化,前面不会多出其他的字符串。
    2. 我之前也曾经写过id名字会变的原因是因为system.web.ui.usecontrol的原因。加了模板会出现这样的问题
    3. 要想得到变化了的控件id的名字,可以<%txtName.ClientID%>得到控件id    ,还有一种就是我上面写的代码就是用属性给控件命名就可以了。但是属性命名有点麻烦。

     

     

     

    你可能感兴趣的:(控件id名字的变了,怎么获取控件id的名字,用ClientID这样得到id名字)