脚本代码:        <script type="text/javascript">
        <!--
        function fnload()
        { 
            alert('222');
            //var imagestr=window.parent.dialogArguments;
            ChaffMessage_UpLargeImage.GetImage('ddd');
        }
    -->
    </script>   前台代码:<body onload ="fnload();">
    <form id="form1" runat="server">
            <div style="width:100%; height:100%; text-align:center; vertical-align:middle;">
            <div style="width:100%;text-align:center; vertical-align:middle;">
                <asp:Image ID="imgShow" runat="server"  AlternateText="无图片显示" BorderWidth="0px" />
            </div>
            <div style="width:100%;text-align:center; vertical-align:middle;">
                <input id="btnShut" type="button" value="button" />
            </div>
            </div>
        <%--</ContentTemplate>
        </asp:UpdatePanel>--%>
    </form>
</body>cs代码:    [AjaxPro.AjaxMethod]
    public void GetImage(string str1)
    {
            string imagestr="http://localhost:16991/BSMS/ChaffMessage/GetTemporImg.aspx?ImID=424";
            if (imagestr != string.Empty)
            {
                    string imageid = imagestr.Remove(0, imagestr.LastIndexOf("=") + 1);
                    this.imgShow.ImageUrl = "GetTemporImg2.aspx?ImID=" +imageid.ToString();                
            }
        }
    }
出现错误的语句就是:this.imgShow.ImageUrl = "GetTemporImg2.aspx?ImID=" +imageid.ToString();GetTemporImg2.aspx页面的cs代码:    protected void Page_Load(object sender, EventArgs e)
    {
        this.ShowImage();
    }
    TemporaryImg temporimg = new TemporaryImg();
    TemporImgManage temporimgmng = new TemporImgManage();    private void ShowImage()
    {      
            string imagestr = Request.QueryString["ImID"].ToString();
            int imageid = Convert.ToInt16(imagestr);            temporimg = temporimgmng.GetIamge(imageid);
            Response.ContentType = "application/octet-stream";
            Response.BinaryWrite(temporimg.ImageData);
       
    }请各位帮忙看看,问题在哪

解决方案 »

  1.   

    这个错误大部分都是空值引发的!debug调试!!
      

  2.   

    针对你的代码,发现有如下需修改之处
    1.因为你使用的是AjaxPro的框架,所以被标明 [AjaxPro.AjaxMethod]
    的方法内是不能使用页面上的任何控件的,所以在GetImage()这个方法内根本无法调用imgShow这个控件,也不恩那个给它赋值
    2.[AjaxPro.AjaxMethod]这种方法最好有返回值,不然它执行的错误与否,我们根本无法得知
    3.看你代码,你大概是想做个验证码的东西,建议把GetTemporImg2.aspx这个页面使用ashx文件,这个输出图片更好,效率更高
      

  3.   

    this.imgShow.ImageUrl = "GetTemporImg2.aspx?ImID=" +imageid.ToString();
    后台this.imgshow这也能用
      

  4.   

    string imagestr = Request.QueryString["ImID"].ToString();
    int imageid = Convert.ToInt16(imagestr);
    是否有值