Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am Creating a Button Dynamically in Asp.net how can i add existing css style to the dynamic button
i want to change the button color on Mouse hover and Mouse focus
i tried in so many ways like:
C#
Button btn1 = new Button();
btn1.CssClass = "btnmbl1";
btn1.Attributes.Add("href", "../Styles/style.css");
btn1.Attributes["CssClass"] = "btnmbl1";
//btn1.Attributes.Add("CssClass", "btnmbl1");
btn1.Attributes.Add("type", "text/css");
btn1.Attributes.Add("rel", "btnmbl1");

but no luck plz help me
Thank u
Posted
Updated 8-Aug-14 0:19am
v2

1 solution

Please try the below code and let me know :


btn1.Attributes.Add("cssClass", "yourCSSSstyle");

Happy Coding :)
 
Share this answer
 
Comments
Member 10924493 8-Aug-14 6:41am    
Sorry its not working
SRK90 8-Aug-14 6:43am    
are you getting any error or your page is not getting displayed based on CSS.
Please post your CSS here.
Member 10924493 8-Aug-14 6:58am    
I am not getting any error but css is not applied,I have a seperate Style class in my website in that i wrote my css like

.btnmbl1
{
font-weight: bold;
font-size: 15px;
color: Black;
font-family: Calibri;
width: 150px;
height: 70px;
border-style: none;
background-image:url(../images/Button_Mobile_R2.gif);
}
.btnmbl1:focus, .btnmbl1:hover
{
background-image:url(../images/Button_Mobile_R2_1.gif);
}
SRK90 8-Aug-14 7:05am    
In case if you are giving background Image through CSS. then make sure that you have placed the respective image in the Style or your CSS folder (where you have kept your CSS)and dont place the image in Image folder and give that path in CSS..... Please try in that way and let me know.
Member 10924493 8-Aug-14 7:12am    
but the same css working fine with other buttons which are created in .aspx page,when im using css for dyamic button like as u told

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900