Asp.net Ajax UpdatePanel中图像无自动刷新问题

为实现网站注册验证码更新,图像是固定的,但通过CheckCode 类改变图像内容。
如果 <asp:Image ID="Image1" runat="server"  />
      <asp:Button ID="Button1"  runat="server" OnClick="Button1_Click" Text="button"  />

不放在UpdatePanel中每次单击Button1都可改变内容,但放在UpdatePanel中则不行(图片内容有改变的了,但就是Image没有刷新内容。

C# code
   
   
   
   
< form id = " form1 " runat = " server " > & nbsp; < asp:ScriptManager ID = " ScriptManager1 " runat = " server " > </ asp:ScriptManager > < asp:UpdatePanel ID = " UpdatePanel1 " runat = " server " > < ContentTemplate > < asp:Image ID = " Image1 " runat = " server " /> < asp:Button ID = " Button1 " runat = " server " OnClick = " Button1_Click " Text = " button " /> & nbsp; </ ContentTemplate > </ asp:UpdatePanel > </ form > protected void Button1_Click( object sender, EventArgs e) { CheckCode checkcode = new CheckCode(); checkcode.CreateCheckCodeImage( " ~/images/CheckCode.jpg " ); // 更改CheckCode.jpg 内容 Image1.ImageUrl = " ~/images/CheckCode.jpg " ; }
   
   
   
   
后来在CSDN上得到帮助:
   
   
   
   
protected void Button1_Click(object sender, EventArgs e)
    {
        Random rd = new Random();
        CheckCode checkcode=new CheckCode();
        checkcode.CreateCheckCodeImage("~/images/CheckCode.jpg");
      Image1.ImageUrl="~/images/CheckCode.jpg?s="+rd.Next();
    }
   
   
   
   
这样就可以了,原来以为只有网页等文件才能加参数~~

你可能感兴趣的:(Ajax,image,server,asp.net,asp,button)