Nishant Kumar
Nishant Kumar

Reputation: 6083

AsyncPostBackTrigger control in ajax

        <div id="divAnswerHeader">
          <div  id="divAnswerSubHeader">
            <h2><asp:Label ID="lblTotalAnsw" runat="server" Text=""></asp:Label> Answers</h2>
            <div id="divTabs">
                <asp:LinkButton ID="oldestAnswer" runat="server" title="Answers in the order they were given" OnClick="oldest_click">oldest</asp:LinkButton>
                <asp:LinkButton ID="newestAnswer" runat="server" title="Most recent answers first" OnClick="newest_click">newest</asp:LinkButton>
                <asp:LinkButton ID="votesAnswer" runat="server" title="Answers with the most votes first" OnClick ="votes_click">votes</asp:LinkButton>
                </div>
              </div>
            </div>

    <asp:UpdatePanel ID="upPnlLMList" runat="server">
    <ContentTemplate> 

      // code.........

     </ContentTemplate>
     <Triggers> 
       <asp:AsyncPostBackTrigger ControlID="oldestAnswer" EventName="Click" /> 
       <asp:AsyncPostBackTrigger ControlID="newestAnswer" EventName="Click" />
       <asp:AsyncPostBackTrigger ControlID="votesAnswer" EventName="Click" />
     </Triggers> 
   </asp:UpdatePanel> 

in code behind file i have written........... protected void oldest_click(object sender, EventArgs e) {

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

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

    } 

when i click on newest , oldest , votes then page_load event fire while i have allready define asynchronous postback so i want to prevent fire page_load event how i will do.

Upvotes: 0

Views: 2969

Answers (2)

Zain Shaikh
Zain Shaikh

Reputation: 6043

the Page_Load event will always fire, you can try wrapping your code inside following

if (HttpContext.Current.Request.Headers["x-microsoftajax"] == null)
{
// your code here
}

Upvotes: 0

Rebecca Chernoff
Rebecca Chernoff

Reputation: 22605

For a partial postback, the page life cycle is still fully intact. Page_Load still firing is by-design.

http://encosia.com/2007/10/24/are-you-making-these-3-common-aspnet-ajax-mistakes/

What you can do is in your Page_Load event handler, check if you are in the middle of a partial postback.

if (ScriptManager.GetCurrent(this).IsInAsyncPostBack) 

Upvotes: 3

Related Questions