Stuyvenstein
Stuyvenstein

Reputation: 2447

ASP.NET Prevent updatepanel in user control from causing main page load to execute

I have an ASP.NET Usercontrol that contains an updatepanel. When I fire a postback in the updatepanel, it fires the page_load event of the page containing the usercontrol, but the page does not refresh like it normally would (without using an updatepanel). I want to know if I can stop this from happening, and if so, how?

Below is the updatepanel code:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="testControl.ascx.cs" Inherits="WebApplication1.testControl" %>

<asp:ScriptManager runat="server" id="smTest"></asp:ScriptManager>
<asp:UpdatePanel runat="server" ID="updTest" ChildrenAsTriggers="true" UpdateMode="Conditional">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnTest" />
    </Triggers>
    <ContentTemplate>
        <asp:Button runat="server" ID="btnTest" Text="test" />
    </ContentTemplate>
</asp:UpdatePanel>

Upvotes: 2

Views: 1037

Answers (1)

VDWWD
VDWWD

Reputation: 35514

You can check if the PostBack is triggered by an UpdatePanel in the Page_load of the Page and/or UserControl. But you cannot stop the execution of Page_Load.

protected void Page_Load(object sender, EventArgs e)
{
    if (ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack)
    {
        //updatepanel page load
    }
    else
    {
        //normal page load
    }
}

Upvotes: 2

Related Questions