UpdatePanel局部刷新


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

 <asp:ScriptManager ID="ScriptManager1" runat="server">
                                    </asp:ScriptManager>
                                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                        <ContentTemplate>
                                            <%-- <select id="selectGame" style="width: 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);
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM