How to edit CSS style of a div using C# in .NET

后端 未结 9 1642
心在旅途
心在旅途 2020-12-03 09:26

I\'m trying to grab a div\'s ID in the code behind (C#) and set some css on it. Can I grab it from the DOM or do I have to use some kind of control?

9条回答
  •  北荒
    北荒 (楼主)
    2020-12-03 10:07

    Add the runat="server" attribute to it so you have:

    Saving...

    That way you can access the class attribute by using:

    formSpinner.Attributes["class"] = "classOfYourChoice";
    

    It's also worth mentioning that the asp:Panel control is virtually synonymous (at least as far as rendered markup is concerned) with div, so you could also do:

    
        
        

    Saving...

    Which then enables you to write:

    formSpinner.CssClass = "classOfYourChoice";
    

    This gives you more defined access to the property and there are others that may, or may not, be of use to you.

提交回复
热议问题