UpdatePanel局部刷新

前台代码:注意ScriptManager,和UpdatePanel是配套使用的。在ContentTemplate中写局部刷新内容

 <asp:ScriptManager ID="ScriptManager1" runat="server">
                                    </asp:ScriptManager>
                                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                        <ContentTemplate>
                                            <%-- <select id="selectGame" style=" 150px;" onchange="Server_Data()">
                                    </select>--%>
                                            <table>
                                                <tr>
                                                    <td style="padding-left: 0PX">
                                                        <asp:DropDownList ID="ddlGame" runat="server" Width="150px" AutoPostBack="True" OnSelectedIndexChanged="ddlGame_SelectedIndexChanged">
                                                        </asp:DropDownList>
                                                    </td>
                                                    <td>
                                                        充值服务区:
                                                    </td>
                                                    <td style="padding-left: 27PX">
                                                        <asp:DropDownList ID="ddlServer" runat="server" Width="150px">
                                                            <asp:ListItem>请选择</asp:ListItem>
                                                        </asp:DropDownList>
                                                    </td>
                                                </tr>
                                            </table>
                                        </ContentTemplate>
                                    </asp:UpdatePanel>

后台:ScriptManager.RegisterStartupScript这个是调用前台JS的方法。

        protected void ddlGame_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlGame.SelectedIndex != 0 && Request["dept"] != null)
            {
                string deptID = Request["dept"];
                string whereStr = " game_id='" + ddlGame.SelectedValue + "' and plat='" + new OA.Count.Model.PlatType().GetTable(" deptID=" + deptID).Rows[0]["name"] + "'";
                Common.AspNetControl.BindDropDownList(ddlServer, new Game.Model.ServerInfo().GetTable(whereStr));

            }
            else
            {
                ddlServer.Items.Clear();
                ddlServer.Items.Add("请选择");
            }

            ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "updatePanel1show", "change_css()", true);
        }
原文地址:https://www.cnblogs.com/zgaspnet/p/2950183.html