UpdateProgress的AssociatedUpdatePanelID属性


<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="Conditional">
<ContentTemplate>
<%=DateTime.Now%><asp:ButtonID="Button1"runat="server"Text="Button"OnClick="Button1_Click"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTriggerControlID="Button1"/>
</Triggers>
</asp:UpdatePanel>

<asp:UpdateProgressID="UpdateProgress1"runat="server"AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<span>123</span>
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanelID="UpdatePanel2"runat="server"UpdateMode="Conditional">
<ContentTemplate>
<%=DateTime.Now%><asp:ButtonID="Button2"runat="server"Text="Button"OnClick="Button1_Click"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTriggerControlID="Button2"/>
</Triggers>
</asp:UpdatePanel>

<asp:UpdateProgressID="UpdateProgress2"runat="server"AssociatedUpdatePanelID="UpdatePanel2">
<ProgressTemplate>
<span>321</span>
</ProgressTemplate>
</asp:UpdateProgress>

上面的代码是实现,点击Button1显示123 ,点击Button2显示321,

关键点在于 Button位置,如果Button在<ContentTemplate>中,则UpdateProgress中的内容可 以显示,如果说Button的位置在<ContentTemplate>外,既UpdatePanel的外部的话, UpdateProgress中的内容就不会显示了!

方法二:

如果Button的位置必需在UpdatePanel的外部的话,就得运用PageRequestManager中的initializeRequest事件和endRequest事件,代码如下:


<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><Triggers>
<asp:AsyncPostBackTriggerControlID="Button1"EventName="Event"/>
</Triggers>


<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->varprm=Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
varpostBackElement;
functionInitializeRequest(sender,args)
{
if(prm.get_isInAsyncPostBack())
args.set_cancel(
true);
postBackElement
=args.get_postBackElement();

if(postBackElement.id=='Button1')
$get(
'UpdateProgress1').style.display='block';
}
functionEndRequest(sender,args)
{
if(postBackElement.id=='Button1')
$get(
'UpdateProgress1').style.display='none';
}

原文:

http://www.codeproject.com/KB/ajax/UpdateProgress.aspx

你可能感兴趣的:(progress)