更新パネル内に 2 つのボタンがあります。更新の進行状況をトリガーし、ボタンのクリックごとに .gif 画像を表示する必要があります。
2 に答える
プログレス コントロールの AssociatedUpdatePanelID プロパティを設定することにより、UpdateProgress コントロールを単一の UpdatePanel コントロールに関連付けることができます。その場合、UpdateProgress コントロールは、関連する UpdatePanel コントロール内でポストバックが発生した場合にのみメッセージを表示します。
長い検索、試行錯誤の後、私は自分に合ったものを思いつきました.
更新パネルで Javascripting とデュアル パネルを組み合わせる必要があります。
これは VB.NET で行われている
ことに注意してください 私の例ではマスターページを使用していることに
注意してください ボタンとパネルの ID がハードコードされていることに注意してください (理想的ではありません)
これはコードビハインドです..
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
registerscript()
Else
System.Threading.Thread.Sleep(5000)
End If
End Sub
Private Sub registerscript()
Dim clientscriptname As String = "popup"
Dim clientscripttype As Type = Me.GetType()
Dim cs As ClientScriptManager = Page.ClientScript
'checck if clienscript is already registered, if not register it
If Not (cs.IsClientScriptBlockRegistered(clientscripttype, clientscriptname)) Then
Dim myscript As New StringBuilder
myscript.AppendLine("<script language=" & Chr(34) & "javascript" & Chr(34) & " type=" & Chr(34) & "text/javascript" & Chr(34) & ">")
myscript.AppendLine(" var prm = Sys.WebForms.PageRequestManager.getInstance();")
myscript.AppendLine(" prm.add_initializeRequest(InitializeRequest);")
myscript.AppendLine("prm.add_endRequest(EndRequest);")
myscript.AppendLine("var postBackElement;")
myscript.AppendLine("function InitializeRequest(sender, args) {")
myscript.AppendLine("postBackElement = args.get_postBackElement();")
myscript.AppendLine(" $get('ctl00_ctl00_Centerofpage1_Main_Panel2').style.display = 'none'; ")
myscript.AppendLine(" $get('ctl00_ctl00_Centerofpage1_Main_Panel4').style.display = 'none'; ")
myscript.AppendLine("if (postBackElement.id == 'ctl00_ctl00_Centerofpage1_Main_Btn1') {")
myscript.AppendLine(" $get('ctl00_ctl00_Centerofpage1_Main_Panel2').style.display = 'block'; ")
myscript.AppendLine(" $get('ctl00_ctl00_Centerofpage1_Main_Panel4').style.display = 'none'; ")
myscript.AppendLine(" }")
myscript.AppendLine("else ")
myscript.AppendLine(" {")
myscript.AppendLine(" $get('ctl00_ctl00_Centerofpage1_Main_Panel2').style.display = 'none'; ")
myscript.AppendLine(" $get('ctl00_ctl00_Centerofpage1_Main_Panel4').style.display = 'block'; ")
myscript.AppendLine(" }")
myscript.AppendLine("}")
myscript.AppendLine("function EndRequest(sender, args) {")
myscript.AppendLine("if (postBackElement.id == 'ctl00_ctl00_Centerofpage1_Main_Btn1') {")
myscript.AppendLine(" $get('ctl00_ctl00_Centerofpage1_Main_Panel2').style.display = 'none'; ")
myscript.AppendLine(" $get('ctl00_ctl00_Centerofpage1_Main_Panel4').style.display = 'none'; ")
myscript.AppendLine("}")
myscript.AppendLine("}")
myscript.AppendLine(" </script>")
cs.RegisterStartupScript(clientscripttype, clientscriptname, myscript.ToString, False)
End If
End Sub
これは aspx のメイン ページです。
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Title" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Main" Runat="Server">
<cc1:toolkitscriptmanager id="ScriptManager1" runat="server">
</cc1:toolkitscriptmanager>
<asp:UpdatePanel ID="UPL1" runat="server" UpdateMode="Conditional" >
<ContentTemplate >
<asp:Button ID="Btn1" runat="server" Text="Test1" />
<asp:Button ID="Btn2" runat="server" Text="Test2" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UPG1" runat="server" AssociatedUpdatePanelID="UPL1" Visible="true" >
<ProgressTemplate >
<asp:Panel ID="Panel1" CssClass="overlay" runat="server">
<asp:Panel ID="Panel2" CssClass="loader" runat="server" >
.BTN1 : form posting in progress.
<br />
<asp:Image ID="LoadImage" runat="server" ImageUrl="../Masterpages/images/updateprogress/ajax-loader.gif" />
</asp:Panel>
<asp:Panel ID="Panel4" CssClass="loader" runat="server" >
.BTN2 : form posting in progress.
<br />
<asp:Image ID="LoadImage2" runat="server" ImageUrl="../Masterpages/images/updateprogress/ajax-loader.gif" />
</asp:Panel>
</asp:Panel>
</ProgressTemplate>
</asp:UpdateProgress>
</asp:Content>
JavaScript コードは updatepanel のポストバック操作をインターセプトし、それに応じてそれぞれのパネルを表示または非表示にします。
Cssclass=Overlay と CssClass=Loader は、ページを不透明にし、フィードバックを中央に配置するための CSS スタイルです。
ボタン 1 を押すと ...
ボタン2を押す