本文介绍了更新或刷新用户控件whitout刷新所有页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在usercontrol中的代码:

hi this is my code in usercontrol :

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Captcha.ascx.cs" Inherits="Controls_Captcha" %>
<style type="text/css">
    .auto-style1 {
        width: 100%;
    }
    .auto-style2 {
        width: 203px;
    }
</style>
<asp:UpdatePanel runat="server" ID="UpdatePanel1" >
    <ContentTemplate>
<table class="auto-style1">
    <tr>
        <td class="auto-style2">
            <asp:Image ID="Image1" runat="server" Height="100px" Width="200px" />
        </td>
        <td>
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
        </td>
    </tr>
</table>
        </ContentTemplate>
</asp:UpdatePanel>







protected void Page_Load(object sender, EventArgs e)
   {

       if (!IsPostBack)
       {
           GivImage();
       }

   }

   private void GivImage()
   {
       try
       {

               bitmap = new Bitmap(200, 100, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
               Point img = new Point(200, 100);
               creatImage(bitmap);
               string virtualFolder = "~/GigPics/";
               string physicalFolder = Server.MapPath(virtualFolder);
               bitmap.Save(physicalFolder + "7514bd.gif", ImageFormat.Gif);
               Image1.ImageUrl = virtualFolder + "7514bd.gif";
               Graphic.Dispose();
               bitmap.Dispose();

       }
       catch (Exception) { throw; }
   }





现在我在测试页面中使用此控件:



now i use this control in test page :

<div>
    <asp:UpdatePanel runat="server" ID="up1">
        <ContentTemplate> <NezamControl:Captcha  runat="server" ID="Captcha" />  </ContentTemplate>
    </asp:UpdatePanel>

</div>





现在我想要当我点击Button conrol变为刷新更改图片whiteout刷新所有页面测试我该怎么做



now i want when i click on Button conrol become refresh for change picture whiteout refresh all pages test how can i do it

推荐答案

Use this and no require of update panel

(1) Remove Update panel and set
-------------------------------

<table class="auto-style1">
                <tr>
                    <td class="auto-style2">
                        <asp:Image ID="Image1" runat="server" Height="100px" Width="200px" />
                    </td>
                    <td>
                        <asp:Button ID="Button1" runat="server" OnClientClick="javascript:GivImage(); return false;" Text="Button" />
                    </td>
                </tr>
</table>

(2) Add jquery refrence and some javascript code
---------------------------------------------------
 <script src="../Script/jquery-1.6.4.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
 function GivImage()
{




这篇关于更新或刷新用户控件whitout刷新所有页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 21:28
查看更多