简体   繁体   English

更改母版页内容而无需多次加载页面

[英]Change Master Page Content without loading page multiple times

I have Master and Content Page.The Layout is like Header and Footer are in Master page and rest contents are in content/child page. 我有母版页和内容页。版式就像页眉和页脚在母版页中,其余内容在内容/子页中。

Now I want to change the header and footer of master page dynamically.To do this,I have coded Page_load event of master page. 现在,我想动态更改母版页眉和页脚。为此,我编写了母版页Page_load事件。

But Actual problem comes that when Master page's header and footer changes,the page loads multiple times.. 但是实际问题是,当母版页眉的页眉和页脚更改时,该页面将加载多次。

Is there any way to solve this problem.. I want to change header and footer of master page for specific time without refreshing content page. 有什么办法可以解决此问题。。我想在不刷新内容页面的情况下,更改特定时间的母版页眉和页脚。

I have seen many post, but i did not find any accurate answer.. 我看过很多帖子,但没有找到准确的答案。

My code is : this is the page_load event of master page .. 我的代码是:这是母版页的page_load事件。

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DIVHeader.InnerHtml = obj.getHeaderHTMLFinal();
            DIVFooter.InnerHtml = obj.getFooterHTMLFinal();
        }
    }

Where do you want to change the footer on the Master Page? 您要在哪里更改母版页上的页脚?

You could wrap the header and footer in ContentPlaceholder controls and adjust them in client pages directly. 您可以在ContentPlaceholder控件中包装页眉和页脚,然后直接在客户端页面中对其进行调整。

You can also interact with the Master Page in client pages in code behind via the Page.Master property. 您还可以通过Page.Master属性通过代码与客户端页面中的母版页进行交互。

Try to use an updatepanel. 尝试使用一个更新面板。 You can update the content of the panel without reload the whole page. 您可以更新面板的内容,而无需重新加载整个页面。

If in your header or footer you do not have controls that triggers an update then you can manual trigger the update of the panel from code behind using conditional update. 如果在页眉或页脚中没有触发更新的控件,则可以使用条件更新从背后的代码手动触发面板的更新。

hope that helped. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM