当Runat =" Server"时,我如何使用Css文件 [英] How I Use From Css File When Runat="Server"

查看:74
本文介绍了当Runat =" Server"时,我如何使用Css文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在runat =server上设置用户控件中的元素。

但是,当我在runat =server上设置我的元素时,不要在我的元素上运行我的css文件

 <   link     href   = 样式/ showNewsControlStyle.css    rel   =  stylesheet    type   =  text / css   < span class =code-keyword> /  >  



和:

 <   asp:Labe l     ID   =  lblTiltTopicViewer    runat   =  server >  <   / asp:标签 >  



css代码:

 lblTiltTopicViewer  
{
width 450px;
height auto;
方向 rtl;
border solid 1px black;
}

解决方案

这是因为服务器ID与客户端ID不同。



有两种方法可以解决这个问题:



  • 在CSS中使用类而不是ID:替换 #lclTiltTopicViewer 中的到点然后使用 CssClass 属性将CSS应用于您的元素:

     <   asp:标签    ID   =  lblTiltTopicViewer    runat   =  server    CssClass   =  lblTiltTopicViewer >  <   / asp:Label  >  



  • 或,通过在元素中添加 ClientIDMode =Static,确保客户端ID与服务器ID相同:

     <   asp:标签    ID   =  lblTiltTopicViewer    runat   =  server    ClientIDMo de   = 静态 >  <   / asp:Label  > < /跨度> 


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

<link href="Styles/showNewsControlStyle.css" rel="stylesheet" type="text/css" />


and :

<asp:Label ID="lblTiltTopicViewer" runat="server"></asp:Label>


css Code:

 #lblTiltTopicViewer
{
	width:450px;
	height:auto;
	direction:rtl;
	border:solid 1px black;
}

解决方案

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: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:Label ID="lblTiltTopicViewer" runat="server" ClientIDMode="Static"></asp:Label>


这篇关于当Runat =&quot; Server&quot;时,我如何使用Css文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆