我是asp.net新手,有这么个问题
我建了个简单的网站,只有一个defaul.aspx
 protected void Page_Load(object sender, EventArgs e)
    {
       
        System.Drawing.Image  img = Bitmap.FromFile("C://222.bmp");
        Response.ContentType = "image/png";
        System.IO.MemoryStream MS = new System.IO.MemoryStream();
        img.Save(MS, System.Drawing.Imaging.ImageFormat.Jpeg);
        
        img.Dispose();
        byte[] buffer = MS.ToArray();
        Response.BinaryWrite(buffer);    }
这段代码可使主页面返回一个图片222.bmp而我在defaul.aspx.cs中设计的按钮,image控件等,就看不见了我连这个defaul.aspx.cs也贴出来:<head runat="server">
    <title>三维</title>
    <style type="text/css">
        #form1
        {
            height: 290px;
            width: 256px;
        }
        .style1
        {
            width: 100%;
            height: 314px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
   <asp:ImageButton ID="ImageButton2" runat="server" 
            ImageUrl="~/PNG/back_alt.png"         
         style="z-index: 1; top: 53px; position: absolute; width: 28px; height: 33px; right: 479px;" />
    
    <asp:Image ID="Image1" runat="server" Height="285px" Width="252px" 
        onload="Image1_Load" />
    </form>
    
</body>
现在的奇怪问题是,我显示出图片后,设计好的image和imagebutton都看不见了,若是把显示图片的代码注释掉,当然这些控件就出来了。图片很小,不至于把空间盖住,所以不是盖住的原因。

解决方案 »

  1.   

    System.Drawing.Image  img = Bitmap.FromFile("C://222.bmp"); 
            Response.ContentType = "image/png"; 
    晕,上面bmp,下面png
      

  2.   

    Response.ContentType = "image/JPG"; 
      

  3.   

    不能这样写,好像Response.BinaryWrite这个方法全清空输出还是?大概就是这个意思,具体的不知道
      

  4.   

    先把你的css代码注释掉来看看 估计就是你的css问题~~
      

  5.   

    小女子试了以上的方法,都不行啊。唉,我只是个接手asp.net一星期的小小小菜鸟,问题勉强解决了。我是这样解决的:添加一个新的web窗体 default2.aspx在default.aspx里this.Image1.imageURL="~default2.aspx";在default2.aspx的page_load里 System.Drawing.Image img = 图像来源
    Response.ContentType = "image/png";
    System.IO.MemoryStream MS = new System.IO.MemoryStream();
    img.Save(MS, System.Drawing.Imaging.ImageFormat.Jpeg);
    img.Dispose();
    byte[] buffer = MS.ToArray();
    Response.BinaryWrite(buffer);这样default.aspx里就可以看见按钮了,而且image上还能显示“图像来源”里的图像;现在我点default.aspx页面上的按钮,需要实现更换图像,而且“图像来源”是从网络上另一台机器远程调来的,所以是动态的。问题在哪里呢?调试的时候,我每次点按钮,地址栏始终是http://localhost:3192/WebSite/Default.aspx,也就是说页面控制权在default,但同时我可以看到状态栏在显示:“正在下载http://localhost:3192/WebSite/Default2.aspx…………”“……”代表的是参数,也就是此时正在从default2下载以填充image,当然这样是正常的,但效果上,是在我按下按钮和default2的图像下载完之间的空隙时间,整个页面时白的,因此两张图呈现之间的跳跃性非常大,而我要的是要连续的效果,最好是在图像下载完之前,原来的图像不要消失,等defautl2从网络另一台机器调过来图片,填充default中的image控件的imageURL之后,再替换不知道我有没有说清楚,汗一个!!!再次谢谢各位高手了