Cấp bậc tác giả:

DOTNET

Làm thế nào để Delay Load trong UpdatePanel sử dụng Control UpdateProgress

Được viết bởi webmaster ngày 10/10/2013 lúc 07:03 PM
Bài trước Tôi đã hướng dẫn bạn Làm thế nào để Delay Load trong UpdatePanel sử dụng Timer Control. Bài này Tôi cũng sẽ hướng dẫn sử dụng UpdatePanel nhưng kết hợp với Control UpdateProgress.
  • 0
  • 7658

Làm thế nào để Delay Load trong UpdatePanel sử dụng Control UpdateProgress

Bài trước Tôi đã hướng dẫn bạn Làm thế nào để Delay Load trong UpdatePanel sử dụng Timer Control. Bài này Tôi cũng sẽ hướng dẫn sử dụng UpdatePanel nhưng kết hợp với Control UpdateProgress.

Đầu tiên dựng Layout:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Example1.aspx.cs" Inherits="AllAboutDelayLoading_Example1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<script language="javascript" type="text/javascript">
    function pageLoad(sender, e) {
        if (!e.get_isPartialLoad()) {  
            __doPostBack('<%= upUpdatePanel.ClientID %>', 'aaaa');
        }
    }
</script>
<table>
<tr>
<td><img id="i1" src="img1.JPG" /></td>
<td><img id="i2" src="img2.JPG" /></td>
</tr>

<tr>
<td><img id="i3" src="img3.JPG" /></td>
<td style="background-color:Silver; border:dashed; ">
    <asp:UpdatePanel ID="upUpdatePanel" runat="server" UpdateMode="Conditional" 
        onprerender="upUpdatePanel_PreRender" >
    <ContentTemplate>
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        <br /> 
        <asp:LinkButton ID="LinkButton1" runat="server" Enabled="false" ForeColor="Black" Font-Bold="true" Font-Size="Large" onclick="LinkButton1_Click">LinkButton disabled so far</asp:LinkButton>
    </ContentTemplate>
    </asp:UpdatePanel>
    <asp:UpdateProgress ID="updProgressTab" runat="server" AssociatedUpdatePanelID="upUpdatePanel" >
     <ProgressTemplate>
        <div style="position: relative; top: 50%; text-align: center;">
            <asp:Image ID="imgLoading" runat="server" ImageUrl="simple.gif" Width="34px" Height="30px" />Refreshing...
        </div>
     </ProgressTemplate>
</asp:UpdateProgress>
</td>
</tr>
</table>
</asp:Content>

Trong trang CS thực hiện các hàm sau để xử lý:
protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Label1.Text = "Link Button Clicked";
    }

protected void upUpdatePanel_PreRender(object sender, EventArgs e)
    {
        if (Request["__EVENTTARGET"] == upUpdatePanel.ClientID && Request.Form["__EVENTARGUMENT"] == "aaaa")
        {
            System.Threading.Thread.Sleep(6000);
            LinkButton1.Enabled = true;
            LinkButton1.Text = "Enabled Now";
        }
    }

Nguồn bài viết: DOTNET.VN

BÌNH LUẬN BÀI VIẾT

Bài viết mới nhất

LIKE BOX

Bài viết được xem nhiều nhất

HỌC HTML