none
动态生成Image,不显示图片 RRS feed

  • 问题

  • <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplicationTest.WebForm2" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:Panel ID="pnlShow" runat="server">
        </asp:Panel>
        </form>
    </body>
    </html>
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace WebApplicationTest
    {
        public partial class WebForm2 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                Image img = new Image();
                img.ImageUrl = @"E:\Band.jpg";
                pnlShow.Controls.Add(img);
            }
        }
    }


    明明E:\Band.jpg有这个文件,为什么浏览器里不显示这个图片

    浏览器的源文件是

     
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head><title>
     
    </title></head>
    <body>
        <form method="post" action="WebForm2.aspx" id="form1">
    <div class="aspNetHidden">
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNTA3NjE3NzI4ZGS0Ysnrbgw+H771xNEWjoiJwtUvncOgQ1vxiZxN7jNn7w==" />
    </div>
     
        <div id="pnlShow">
    	
        <img src="E:\Band.jpg" />
    </div>
        </form>
    </body>
    </html>
    
    


    2012年9月7日 1:45

答案

全部回复