简体   繁体   中英

ContentPlaceHolder in UpdatePanel

I have very simple a ajax enabled asp .net website with masterpage. I have a menu in master page and the other pages appear in MainContent placeholder. I have the following code.But when I click to the menu items i can see that sometimes page postbacks.

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always"> 
   <ContentTemplate>
       <asp:ContentPlaceHolder ID="MainContent" runat="server" />
   </ContentTemplate>

How can i prevent the postback and the partial load of the page ? I have searched the stackoverflow but all the solutions are same as what i do as far as i see. Is there something that i need to do ?

Thanks.

Edit: the complete page with the menu items is as follows:

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div class="page">
    <div class="header">
        <div class="title">
            <h1>
                App</h1>
        </div>
        <div class="loginDisplay">
        </div>
        <div class="clear hideSkiplink">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Menu ID="NavigationMenu" runat="server" EnableViewState="false" IncludeStyleBlock="false"
                Orientation="Horizontal" Font-Size="Large" Height="48px" Width="100%" BorderStyle="Dashed">
                <Items>
                    <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home Page" />
                    <asp:MenuItem NavigateUrl="~/DefinePropertyType.aspx" Text="Define PropertyType" />
                    <asp:MenuItem NavigateUrl="~/CreateProperty.aspx" Text="Create Property" />
                    <asp:MenuItem NavigateUrl="~/RiskManagemet.aspx" Text="Risk Managemet" />
                    <asp:MenuItem NavigateUrl="~/InsurancePolicy.aspx" Text="InsurancePolicy" />
                    <asp:MenuItem NavigateUrl="~/Damage.aspx" Text="Damage" />
                </Items>
                <StaticMenuItemStyle ItemSpacing="20px" />
            </asp:Menu>
        </div>
    </div>
    <div class="main">
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always"> 
            <ContentTemplate>
                <asp:ContentPlaceHolder ID="MainContent" runat="server" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    <div class="clear">
    </div>
</div>
<div class="footer">

You need to define the Menu control as async postback trigger of the update panel. Try this

    <asp:updatepanel ID="Updatepanel1" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="NavigationMenu" 
                EventName="MenuItemClick" />
        </Triggers>
        <ContentTemplate>
             <asp:ContentPlaceHolder ID="MainContent" runat="server" />
        </ContentTemplate>
    </asp:updatepanel>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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