Is runat=“server” required for HTML tags which have CSS style built by ASP.NET?

心已入冬 提交于 2019-12-08 07:55:03

问题


I got this div tag who's background image's being set in the CSS using some method like this..

Inline CSS:-

.id0, .mySprite:hover div
    {
        background-image: url(<%=GetImage()%>);
        background-repeat: no-repeat;
        width: 728px;
        height: 243px;

    }

HTML:-

<div class="id0"></div>

Now do I need to set runat="server" in this div tag or not? Coz it's not giving no error but was wondering may be I need to coz the image's path's being fetched from code behind...the image's not appearing in this user control.


回答1:


Well,

  • The "Runat=Server" is not needed at all. The CSS is loaded/associated on the client (in the brwoser) anyway.
  • Sorry, dude, but .CSS files are not evaluated by ASP.NET - so basically, the "url" that the browser gets is <%=GetImage()%>, which obviously the browser can not do anything with.

Result: Does not work. Can not work.




回答2:


Why do you need the server to generate the path? The image path should be relative to the css file so if your css is in project/css/style.css and image is in project/images/myimage.jpg use

background-image: url(../images/myimage.jpg);

Also, use firebug to check what's really being set as the background image. You can also try

background-image: url(../images/myimage.jpg) !important;



回答3:


You are generating the css from server-side code? Or is a simple .css file? If you have .css file the code: background-image: url(<%=GetImage()%>); does not work.

And then, the css rule for div with id id0, you must define it with # not dot (#id0 not .id0)



来源:https://stackoverflow.com/questions/4003032/is-runat-server-required-for-html-tags-which-have-css-style-built-by-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!