【问题标题】:Update panel inside Server Control服务器控制内的更新面板
【发布时间】:2013-11-01 20:16:53
【问题描述】:

我正在尝试通过使用__DePostBack 调用服务器来更新面板内容,HTTP 服务器端被触发但面板不会更新,

更新面板在自定义服务器控件中,它对 PAGE 上下文不熟悉,我只能通过以下方式访问它:FindControl("Update Panel ID")

如何使更新面板更新?

Default.aspx.cs 代码:

protected void Page_Load(object sender, EventArgs e)
{
string _action = this.Request.Params.Get("__EVENTTARGET");
if (_action == "XX")
{
    UpdatePanel pnl = ((UpdatePanel)TabControl1.FindControl("UpdatePanel ID"));
    UserControl uc = (UserControl)LoadControl("MyForm.ascx");
    pnl.ContentTemplateContainer.Controls.Clear();
    pnl.ContentTemplateContainer.Controls.Add(uc);
}
}

Default.aspx 代码:

 <SDMS:TabControl ID="TabControl1" BorderColor="#00F" runat="server" class="tabswrapper">
    <TabPages>
        <SDMS:TabPage ID="TabPage6" runat="server" UpdateContent="UpdatePanel1" Title="Two">
            <TabBody>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>

                    <ContentTemplate>
                </asp:UpdatePanel>
            </TabBody>
        </SDMS:TabPage>
    </TabPages>
</SDMS:TabControl>

如何使更新后的面板更新?

【问题讨论】:

    标签: c# ajax updatepanel web-controls composite-controls


    【解决方案1】:

    如果您想让 UpdatePanel 由 CodeBehind 更新,请使用:

    pnl.Update();
    

    确定您需要在进行更改后调用它。 (例如,您在 UpdatePanel 中添加了一个按钮。)

    因此,您的代码应该可以使用:

    protected void Page_Load(object sender, EventArgs e)
    {
        string _action = this.Request.Params.Get("__EVENTTARGET");
        if (_action == "XX")
        {
            UpdatePanel pnl = ((UpdatePanel)TabControl1.FindControl("UpdatePanel ID"));
            UserControl uc = (UserControl)LoadControl("MyForm.ascx");
            pnl.ContentTemplateContainer.Controls.Clear();
            pnl.ContentTemplateContainer.Controls.Add(uc);
            pnl.Update();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多