开发者

Custom ReferenceID property for buttons and menu classes

For ASP controls - let us say we are using button, is it possible to derive from BUTTON, a derived control a开发者_运维技巧nd create new property called, say , ReferenceID (type say integer) and use that property.

I would like to have a unique id for the control other than the ID we are having


Yes, it is possible and the way you are thinking about it will work but keep in mind that you will have to keep track of the values assigned to this property in ViewState. What I mean is this (untested code):

public class CustomButtom : Button
{

     public int ReferenceID {  
       get {
              if(ViewState["ReferenceID"]!=null)
                return int.Parse(ViewState["ReferenceID"].ToString());
              return -1;
           }
      set  {
             ViewState["ReferenceID"]=value;
           } 

     } 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜