skip to Main Content
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="updatePanel2" runat="server" ChildrenAsTriggers="true">
        <ContentTemplate>
            <asp:Button ID="btnBlock" Text="BlockCalls" runat="server"
                OnClick="btnBlock_Click" Enabled="True" Width="100px" />
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btnBlock" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>

When i click on btnBlock pageload even fires. I don’t want page refresh when user clicks on button

2

Answers


  1. So, If you put the trigger on button click it is normal when you click it to postback and refresh the page.
    If you want to postback without page refresh you should have something like this:

    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="updatePanel2" runat="server">
        <ContentTemplate>
            <asp:Button ID="btnBlock" Text="BlockCalls" runat="server" 
                OnClick="btnBlock_Click" Enabled="True" Width="100px" />
        </ContentTemplate>
    </asp:UpdatePanel>
    

    Either way your Page_Load event will be fired, but you can do this:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //this is page load
        }
        else{
            //this is PostBack
        }
    }
    
    Login or Signup to reply.
  2. You still ALWAYS get a partial page post-back, and the page load event DOES fire each time with update panel – just like it does for any button outside of the update panel.

    So, your page load event should have IsPostBack = false for first page setup code.

    So code inside IsPostBack=False code stub only runs first time.

    So, while the whole page will not re-fresh, and whole page is NOT re-posted? You still get what is called a "partial" page post back – and while only stuff inside panel is posted back to the server? Standard form events STILL fire each time including page load.

    You need to build that page to handle post backs, and introduction of a update panel does NOT fix this requirement.

    If your page can’t survive a post-back, then it will not handle a update panel. So, a update panel does NOT prevent a post-back, but results in what we call a partial post-back.

    So, say if you pop up say a jQuery.UI (or bootstrap) dialog, and do a post-back? Then that dialog will get blown up and out due to the page post back. As noted, update panels STILL do a post-back, but not a full page, and hence the term partial post-back, and thus any server side button or whatever inside of that panel that does a post back? Well, the page load event still fires each time.

    So, while some jQuery and some controls can (and will) go zonkey with a full page post back? And using a update panel can help? Keep in mind that server side events in that update panel still result in post-backs – just not full page ones.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search