开发者

How to add css to a asp.net web application

I am starting a new asp.net web app class (using c#). For my first lab I need to create a simple开发者_JAVA技巧 web page with a couple button. I have already made the page with the buttons and text. When you press the button it needs to change the text color using in-line css. How would I go about adding the in-line css to the button. Would I add some sort of C# code in the button to enable css? I am quite confused how to add the css to the web app. Any ideas?


From your question it sounds like you want to add inline css to some sort of element containing text when you click a Button?

protected void btn_Click(object sender, EventArgs e)
{
   string inlineCss = "your css goes here";

   //I'm assuming the text you want to apply css to is a Label with ID=label
   label.Attributes.Add("style", inlineCss);
}


Try this on click event

        HtmlLink css = new HtmlLink();    
        css.Href = "css/fancyforms.css";    
        css.Attributes["rel"] = "stylesheet";    
        css.Attributes["type"] = "text/css";    
        css.Attributes["media"] = "all";    
        Page.Header.Controls.Add(css);

If needs inline

        txtmyCtrl.Style.Add(HtmlTextWriterStyle.Color,"#33cc45");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜