CSS Style Not Working With ID

后端 未结 3 1356
被撕碎了的回忆
被撕碎了的回忆 2021-01-21 07:49

I am using asp.net/C# for my project.Currently i have a default.aspx page and a master page.The default.aspx page has many controls , and

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-21 08:38

    The client ID is not equal to the ID property of a runat="server" control. To get the ID on the client, you can use the ClientID property.

    On newer ASP.NET versions (starting with version 4), there is also a ClientIDMode property to control the generation.

    So to solve your issue, you could either set ClientIDMode to ClientIDMode.Static or somehow access the ClientID property from code behind and put this value into your CSS definition.

    Alternatively you could also:

    • Put the text box in some container control (e.g. a div) that has no runat="server" and put an ID into this container control, changing your CSS to e.g. #txtContainer input{border:1px solid red}
    • Use the CssClass property of your text box and use this class in your CSS file, instead of the ID.

提交回复
热议问题