当前位置:编程学习 > C#/ASP.NET >>

母版页上背景图片无法显示

您好,我现在在做项目的时候遇上一个问题麻烦您帮忙解决下,
     我在Web用户控件上设了一个背景图片,是可以显示的,但是在把web控件嵌套进主页面上时,背景图片却无法显示,希望您帮忙下
           <td style="font-size: 24pt; background-image: url(../Images/banner2.gif); width: 302px;
            height: 62px; text-align: center"> --------------------编程问答-------------------- 路径不对了吧,你的Images文件夹在根目录下吗?
--------------------编程问答-------------------- 路径的问题。 --------------------编程问答-------------------- ../Images/banner2.gif



/Images/banner2.gif
--------------------编程问答-------------------- 路径问题
--------------------编程问答-------------------- 絕對的路徑問題 --------------------编程问答--------------------  <td style="font-size: 24pt; background-image: url(/Images/banner2.gif); width: 302px; 
            height: 62px; text-align: center">
路径问题 --------------------编程问答-------------------- 但是修改了之后在WEB控件上就不能显示背景图片l --------------------编程问答-------------------- E:\chengbaoBBS\chengbaoBBS\Images
图片是在这个文件夹下了,是说web用户控件的附图路径和主页面上的附图路径不一样吗 --------------------编程问答-------------------- web用户控件附图路径和主页面上的附图路径不一样吗 用户控件和 主页是在一个目录下边吗 ?  同一个目录下的话 路径是一样的. --------------------编程问答-------------------- url(../Images/banner2.gif); 
改为url(/Images/banner2.gif); 应该可以了吧 --------------------编程问答-------------------- 同上 --------------------编程问答-------------------- E:\chengbaoBBS\chengbaoBBS\Common WEB用户控件是在这个文件下的
E:\chengbaoBBS\chengbaoBBS 主页面是在根目录下的,这样路径能一样嘛 --------------------编程问答-------------------- 应该修改那个附图路径呀,是WEB控件还是主页面的呀 --------------------编程问答--------------------       <td style="font-size: 9pt; vertical-align: middle; color: black; font-family: 宋体; text-align: center; background-image: url(../Images/di2.gif); width: 800px; height: 122px;"> 
这是web控件的代码
       
<body>
    <form id="form1" runat="server">
    <div style="background-image: url(Images/bg.gif); background-repeat: repeat">
        <table style="width: 800px;" align="center" border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td style="height: 130px; width: 800px;">
                    <uc1:Header ID="Header1" runat="server" />
                </td>
            </tr>
            <tr align="left">
                <td style="text-align:center; vertical-align: top;">
                <iframe id="mainframe" src="ModuleManage/ModuleInfo.aspx" name="mainframe" frameborder="no" scrolling=no style="width: 800px; height:500px; background-color: #fffcf2;" enableviewstate="true" tabindex="0" marginheight="0" marginwidth="0"></iframe>
                </td>
            </tr>
            <tr>
                <td style="height: 70px; width: 800px;">
                    <uc2:Footer ID="Footer1" runat="server" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
这是主页面的
就是背景不显示 --------------------编程问答--------------------  <td style="font-size: 9pt; vertical-align: middle; color: black; font-family: 宋体; text-align: center; background-image: url(../Images/di2.gif); width: 800px; height: 122px;"> 
这是web控件的代码 
      
<body> 
    <form id="form1" runat="server"> 
    <div style="background-image: url(Images/bg.gif); background-repeat: repeat"> 
        <table style="width: 800px;" align="center" border="0" cellpadding="0" cellspacing="0"> 
            <tr> 
                <td style="height: 130px; width: 800px;"> 
                    <uc1:Header ID="Header1" runat="server" /> 
                </td> 
            </tr> 
            <tr align="left"> 
                <td style="text-align:center; vertical-align: top;"> 
                <iframe id="mainframe" src="ModuleManage/ModuleInfo.aspx" name="mainframe" frameborder="no" scrolling=no style="width: 800px; height:500px; background-color: #fffcf2;" enableviewstate="true" tabindex="0" marginheight="0" marginwidth="0"> </iframe> 
                </td> 
            </tr> 
            <tr> 
                <td style="height: 70px; width: 800px;"> 
                    <uc2:Footer ID="Footer1" runat="server" /> 
                </td> 
            </tr> 
        </table> 
    </div> 
    </form> 
</body> 
--------------------编程问答-------------------- <td style="font-size: 24pt; background-image: url(../Images/banner2.gif); width: 302px; 
            height: 62px; text-align: center">

=======================
是的,路径,你可以用站点当前的目录映射 --------------------编程问答-------------------- 不用再贴代码了,你这问题就是由于路径引起的,修改图片路径就可以了
../表示源文件所在目录的上一级目录,../../表示源文件所在目录的上上级目录,以此类推。
而/前不加任何东西则表示从根目录下开始,如"/Images/pic1.gif"就表示根目录下Images文件夹的pic1.gif
根据这个,你应该可以自己把路径指对了吧 --------------------编程问答-------------------- url(~/Images/banner2.gif) --------------------编程问答-------------------- 肯定是路径的问题。 --------------------编程问答-------------------- 谢谢大家了 --------------------编程问答-------------------- 肯定为路径问题。 --------------------编程问答-------------------- 用户控件中不路径不需要显示图片,用户控件用到主页面上时,图片的路径发主页面为主
../Images/banner2.gif 改为Images/banner2.gif  --------------------编程问答-------------------- 嗯好像css里面写和aspx的写的不一样吧,大家讨论下. --------------------编程问答-------------------- 用服务器路径吧 --------------------编程问答-------------------- 使用绝对路径,我试过了,可以的url(127.0.0.1/gztranstar/images/index.gif) --------------------编程问答-------------------- url(http://127.0.0.1/gztranstar/images/index.gif) --------------------编程问答--------------------
引用 18 楼 zzxap 的回复:
url(~/Images/banner2.gif)


正解 --------------------编程问答-------------------- 路径问题
用绝对路径,如果还不信就在前面加一个"~" --------------------编程问答-------------------- 慢慢改吧  --------------------编程问答-------------------- 肯定的是路径问题~~~ --------------------编程问答-------------------- 楼上们,别乱用 ~/ ,这只有 asp.net 运行时或者带 runat=server 的控件才能解析 --------------------编程问答-------------------- 不要相对用户控件所在目录,要相对使用用户控件的 。aspx 页面所在目录!

用户控件中看不见没关系,。aspx能看见就可以了 --------------------编程问答-------------------- 可能是路径问题吧。我也出现过这种情况。至今还没弄明白。 --------------------编程问答-------------------- 路径问题。 --------------------编程问答-------------------- 你那个用户控件中的图片路径应该对应的是主页面
--------------------编程问答-------------------- 路径问题 --------------------编程问答-------------------- 问题很严重,我也有,不过把路劲的问题解决了之后,VS中可以显示图片出来,可是在浏览器调试就不行了,用IE和OPERA都不行 --------------------编程问答-------------------- 直接把图片拖上来,会自动生成一个地址。
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,