首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

UpdatePanel中局部刷新图片有关问题

2013-09-05 
UpdatePanel中局部刷新图片问题我在UpdatePanel1中添加个图片和button1,button2,label3,在UpdatePanel1外

UpdatePanel中局部刷新图片问题
我在UpdatePanel1中添加个图片和button1,button2,label3,在UpdatePanel1外面添加一个button3和一个lablel2,我写了如下代码

         protected void Page_Load(object sender, EventArgs e)
        {
            Label2.Text = DateTime.Now.ToString();
         }
       protected void Button1_Click(object sender, EventArgs e)
        {
            string StrsqlOne = "select P_PersonnelInformation.CardNo,Name,Sex,Age,Addr,Phone,EventTime,Photo from P_PersonnelInformation inner join P_EventLog on P_PersonnelInformation.CardNo=P_EventLog.CardNo and P_EventLog.ID in(select max(ID) from P_EventLog) where EventTime>'2013-01-11'";
            DataTable dt = DbHelper.Instance.CreateDataTable(StrsqlOne);
            byte[] buffByle = (Byte[])dt.Rows[0]["Photo"];
            int filelength = buffByle.Length;
            //string myUrl = HttpContext.Current.Server.MapPath(this.Request.ApplicationPath) + "TempDownLoad";
            System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath("TempDownLoad"));
            if (file.Exists)
            {
                file.Delete();
            }
            string myUrl = Server.MapPath("TempDownLoad");
            FileStream fs = new FileStream(myUrl, FileMode.OpenOrCreate);
            BinaryWriter w = new BinaryWriter(fs);//以二进制的形式将基元内写入流
            w.BaseStream.Write(buffByle, 0, filelength);//把数据库中的图片二进制添加到BinaryWriter
            w.Flush();
            w.Close();


            Image1.ImageUrl = "~/TempDownLoad";
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            this.Label3.Text = DateTime.Now.ToString();
        }


上面是检索数据库中一个表ID最大值(默认自增的)对应的图片,
button3没有任何事件。
运行后我在数据库插入一条最新数据,点button1后代码运行了,图片却没变,点button2值成功,
点button3后页面刷新了下,然后再点button1发现图片可以改变了。这是什么原因啊。
UpdatePanel 数据库 图片
[解决办法]

        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        </div>
        <asp:UpdatePanel ID="updatepanel1" runat="server">
            <ContentTemplate>
                <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Button1" />
            </Triggers>
        </asp:UpdatePanel>

后台代码

protected void Button1_Click(object sender, EventArgs e)
{
    Button1.Text = Guid.NewGuid().ToString().Substring(0, 4);
}


我这样写的话 button的text是可以改变的
------解决方案--------------------


你的图片是在updatepanel里面还是外面绑定的?
用无刷新的话  他外面的事件是不会触发的
点击外面的按钮时 才会刷新整个页面

热点排行