I need to get css styles from code behind in asp.net c#, haven't found solution on the web, is it possible to get it directly from styles.css file or do I need to workaround?
I'm using themes in my web app, but I also need to do some server processing and I need colours from ccs files,开发者_如何学编程 which are different for each user of course:s
You should be able to retrieve the current styles with the following approach:
var targetElement = document.getElementById("myFancyElement");
var currentStyles = window.getComputedStyle(targetElement, null);
var color = currentStyles["color"];
document.getElementById("myCurrentColor").value = color;
The next step would be to post that color
value back to the server. Which could either get posted as json with an XHR request, or simply set as a form value via a hidden input element, like so:
<input type="hidden" runat="server" name="myCurrentColor" id="myCurrentColor" />
Cs file
protected void Button1_Click(object sender, EventArgs e)
{
Panel1.CssClass = "RedBackground";
Panel1.Style.Add("font-size", "200%");
/// get value back
string pvalue = Panel1.Attributes["class"] ;
or
btn_4.Attributes.CssStyle["property"]
}
Html File
<style type="text/css">
.RedBackground
{
background-color: Red;
}
<asp:Panel ID="Panel1" runat="server">
Hello
</asp:Panel>
精彩评论