如何通过 ContentPage 上的按钮更新 Masterpage 上的 GridView?

发布于 2024-12-04 05:53:18 字数 161 浏览 1 评论 0原文

我有一个 MasterPage,在 UpdatePanel 上有一个 GridView。在我的内容页面之一上,我有一个按钮,它将项目添加到会话中,我希望该项目出现在 MasterPage 上的 Gridview 中。我在 Gridview 中获得了项目,但在刷新或回发或类似问题上遇到问题。有人对此有答案吗?

I have a MasterPage with a GridView on a UpdatePanel. On one of my content pages I have a button which adds items to a session which I want to appear in the Gridview which is on the MasterPage. I'v got the items in the Gridview but have problem with refresh or postback or something like that. Does anyone have an answere to this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜是你 2024-12-11 05:53:18

如果您在更新面板中遇到刷新问题,则意味着回发按钮不在更新面板内,或者面板未手动更新。

对于这种情况,我假设您不能将按钮放在面板内,因为它是内容页面的一部分,因此我建议您将面板的 UpdateMode 设置为条件,并在母版页上使用一些刷新方法。为了在内容页面中看到此方法,请使用此方法创建一些接口,并让母版页使用此接口。

然后在内容页面中获取母版页引用并使用刷新方法。

例如

界面

public interface IMaster
{
    void RefreshPanel();
}

母版页

(注意它使用我们之前创建的IMaster界面)

public partial class MasterPage : System.Web.UI.MasterPage,  IMaster
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Load items from session
    }

    public void RefreshPanel()
    {
        UpdatePanel1.Update();
    }
}

内容页面

public partial class ContentPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

       //Add items to session 
       //....

        //Now refresh the updatepanel on the masterpage
        IMaster masterPage = Master as IMaster;
        masterPage.RefreshPanel();
    }
}

If you have refresh issue in updatepanel, then it means that the post back button is aether not inside the update panel or the panel is not updated manually.

For this case I assume you cant put the button inside the panel as it is part of content page, so i suggest you set panel's UpdateMode to conditional and have some refresh method on your masterpage. In order to see this method in the content page make some Interface with this method and let the masterpage use this interface.

then in the content page take the masterpage referense and consume the refresh method.

e.g.

The interface

public interface IMaster
{
    void RefreshPanel();
}

The masterpage

(note it uses the IMaster interface that we created before)

public partial class MasterPage : System.Web.UI.MasterPage,  IMaster
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Load items from session
    }

    public void RefreshPanel()
    {
        UpdatePanel1.Update();
    }
}

The content page

public partial class ContentPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

       //Add items to session 
       //....

        //Now refresh the updatepanel on the masterpage
        IMaster masterPage = Master as IMaster;
        masterPage.RefreshPanel();
    }
}
远昼 2024-12-11 05:53:18

您需要研究使用事件和委托。基本上,您将在用户控件上创建一个事件,您的母版页将对此做出反应。还有许多其他网站提供示例,因此只需 google ASP.NET Events and Delegates 即可。

You will need to look into using Events and Delegates. Basically, you will create an Event on the Usercontrol which your MasterPage will react to. There are many other websites with examples, so just google ASP.NET Events and Delegates.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文