How do you programmatically apply a css class to an asp.net control?

前端 未结 7 1701
余生分开走
余生分开走 2021-01-16 11:46

I\'m wondering how I can apply a CSS class to an ASP.NET Control (TextBox in this case) through the backend in C#. For example:



        
7条回答
  •  长发绾君心
    2021-01-16 12:30

    Simply create an entry in the ViewDataDictionary for the class.

    The backend would look something like

    ViewData["selectedclass"] =  ? "selected" : "";
    

    And the view would be

        " runat="server" Text="First Name" />  
    

提交回复
热议问题