Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need my element in user control set on runat="server".
but , when i set my element on runat="server" ,do not work my css file on my element
HTML
<link href="Styles/showNewsControlStyle.css" rel="stylesheet" type="text/css" />

and :
ASP.NET
<asp:Label ID="lblTiltTopicViewer" runat="server"></asp:Label>

css Code:
CSS
 #lblTiltTopicViewer
{
	width:450px;
	height:auto;
	direction:rtl;
	border:solid 1px black;
}
Posted
Comments
Jαved 3-Jul-14 5:38am    
Not clear. what you want to do?
do you want to set css to Label?

1 solution

This happens because the server ID is not the same as the client ID.

There are two ways to solve this:

  • Use a class instead of an ID: in your CSS, replace the # in #lblTiltTopicViewer into a dot . and then use the CssClass attribute to apply the CSS to your element:
    ASP.NET
    <asp:Label ID="lblTiltTopicViewer" runat="server" CssClass="lblTiltTopicViewer"></asp:Label>

  • Or, make sure that the client ID is the same as the server ID, by adding ClientIDMode="Static" to your element:
    ASP.NET
    <asp:Label ID="lblTiltTopicViewer" runat="server" ClientIDMode="Static"></asp:Label>
 
Share this answer
 
v2
Comments
Thanks7872 3-Jul-14 5:40am    
+5..! I was about to post the same.
Thomas Daniels 3-Jul-14 5:40am    
Thank you!

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