Set ClientID in asp.net

前端 未结 7 1647
情话喂你
情话喂你 2020-12-19 03:28

Is it possible to set the ClientID of any asp.net server control? How can I do this?

7条回答
  •  余生分开走
    2020-12-19 04:14

    For VS 2010, .NET 4.0:

    If you just try to set ctrl.ClientID="stringID" you will get an Error, saying that ClientID is read only. You can control the value of ClientID using ClientIDMode - which defines the algorithm with which ClientID is set:

    ctrl.ID = "IDstring";
    ctrl.ClientIDMode = ClientIDMode.Static;   //ClientID value is set to the value of ID
    

    The html markup will mark your control's html with the control's ID. Thus you have some degree of control from the code-behind.

提交回复
热议问题