I want to add a style A:Hover to a HyperLink control from code behind.
I can do like this :
HyperLink hlRow = new HyperLink();
hlRow.Style.Add("color", "#000000");
hlRow.Style.Add("text-decoration", "none");
But how can I add styles for A:Hover for the hyperlink control?
Do I need to define a class and associate that class with this control, if yes how?
If you want to add attributes, including the class, you need to set runat="server" on the tag. Thanks, I was sure it would be this simple. @Tyler, no. This adds a new class name to the control.
You can use the CssClass property of the hyperlink:
LiteralControl ltr = new LiteralControl();
        ltr.Text = "<style type=\"text/css\" rel=\"stylesheet\">" +
                    @".d
                    {
                        background-color:Red;
                    }
                    .d:hover
                    {
                        background-color:Yellow;
                    }
                    </style>
                    ";
        this.Page.Header.Controls.Add(ltr);
        this.HyperLink1.CssClass = "d";
                        Use
HyperLink hlRow = new HyperLink();
hlRow.Attributes.Add("Style", "color:#000000");
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With