1. ScriptManager和UpdatePanel控件联合使用可以实现页面局部异步刷新的效果。UpdatePanel用来设置页面中局部异步刷新的区域,它必须依赖于ScriptManager,因为ScriptManager控件提供了客户端脚本生成与管理UpdatePanel的功能。
|
|||||
一、实例一
UpdatePanel内部控件引起的回发,来异步更新当前UpdatePanel内部其他控件的内容。
前台代码如下:
<div id="zcfl" class="field" style="display: none">
<legend class="legend" style="text-align: center;">资产分类</legend>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table class="tablebody">
<tr>
<td>
<span style="padding-left: 9px;">.选好资产大类 ·····→ .再选择具体分类:</span>
</td>
</tr>
<tr>
<td style="text-align: center; padding: 8px 0px;">
<asp:RadioButtonList ID="ddlDl" runat="server" RepeatDirection="horizontal" CssClass="txt radiobutton"
RepeatLayout="Flow" OnSelectedIndexChanged="ddlDl_SelectedIndexChanged" AutoPostBack="True">
<asp:ListItem Value="" Selected="true">固定资产</asp:ListItem>
<asp:ListItem Value="">无形资产</asp:ListItem>
<asp:ListItem Value="">其他</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td id="ddlzczl" style="text-align: center; padding: 12px 0px;">
<asp:RadioButtonList ID="ddlZcfl" runat="server" RepeatDirection="horizontal" CssClass="txt radiobutton"
RepeatLayout="flow">
</asp:RadioButtonList>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
后台代码如下:
protected void ddlDl_SelectedIndexChanged(object sender, EventArgs e)
{
string id = ddlDl.SelectedValue;
switch (id)
{
case "":
GyHelp.BindListN(ddlZcfl, new ZcFlbAction().GetDataBindGdzc(), "text", "value", false, string.Empty, string.Empty); break;
case "":
GyHelp.BindListN(ddlZcfl, new ZcFlbAction().GetDataBindWxzc(), "text", "value", false, string.Empty, string.Empty); break;
default:
GyHelp.BindListN(ddlZcfl, new ZcFlbAction().GetDataBindQtzc(), "text", "value", false, string.Empty, string.Empty);
break;
}
}
注意:
此时ScriptManager的EnablePartialRendering属性应设为true(默认即为true);
UpdatePanel的UpdateMode属性应设为Always(默认即为Always);
UpdatePanel的ChildAsTrigger属性应设为true(默认即为true);
效果如图: