locked
Problem With UpdatePanel RRS feed

  • Question

  • User1637098094 posted

    hi everyone,

    my problem is that i have one updatepanel in aspx page,i set it's updatemode to "conditional" and i sert an asynchpostbacktrigger for it as below:

    as you see i have a button that is outside of updatepanel and my button code behid is : lblTime.Text = DateTime.Now.ToLongTimeString();

    and pageload of the page is:

     protected void Page_Load(object sender, EventArgs e)
            {
                lblTime.Text = DateTime.Now.ToLongTimeString();
                lblUpdatepnel.Text = DateTime.Now.ToLongTimeString();
            }

    when i change the dropdownlist selectedindexchange everything is ok and just the updatepanel content is being updated,but when is lick mybuton to just update lblTime value then the updatepanel content is being updated too,why is it that way although i set the updatemode of updatepanel to conditional??????

      <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
                SelectCommand="SELECT [ID], [NAME] FROM [FAC_Category]"></asp:SqlDataSource>
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"
                DataTextField="Name" DataValueField="ID">
            </asp:DropDownList>
            
            <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /><asp:Label runat="server" ID="lblTime"></asp:Label>

            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:Label runat="server" ID="lblUpdatepnel"></asp:Label>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="DropDownList1"   EventName="SelectedIndexChanged" />
                </Triggers>
            </asp:UpdatePanel>
    Saturday, December 28, 2013 3:22 PM

Answers

  • User-1360095595 posted

    Because the button will cause a full postback which also updates the updatepanel content. 

    What the updatepanel does is always you to conditionally update content based on triggers. So any trigger will ONLY updates the updatepanel. But any other control that causes a postback will also update the updatepanel unless you put that control in a separate updatepanel with updatemode conditional. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 29, 2013 1:22 AM
  • User555306248 posted

    How UpdatePanel Controls Are Refreshed

    The following list describes the property settings of the UpdatePanel control that determine when a panel's content is updated during partial-page rendering.

    • If the UpdateMode property is set to Always, the UpdatePanel control’s content is updated on every postback that originates from anywhere on the page. This includes asynchronous postbacks from controls that are inside other UpdatePanel controls, and postbacks from controls that are not inside UpdatePanel controls.

    • If the UpdateMode property is set to Conditional, the UpdatePanel control’s content is updated when one of the following is true:

      • When the postback is caused by a trigger for that UpdatePanel control.

      • When you explicitly call the UpdatePanel control's Update method.

      • When the UpdatePanel control is nested inside another UpdatePanel control and the parent panel is updated.

      • When the ChildrenAsTriggers property is set to true and any child control of the UpdatePanel control causes a postback. Child controls of nested UpdatePanel controls do not cause an update to the outer UpdatePanel control unless they are explicitly defined as triggers for the parent panel.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 29, 2013 10:38 PM

All replies

  • User-1360095595 posted

    Because the button will cause a full postback which also updates the updatepanel content. 

    What the updatepanel does is always you to conditionally update content based on triggers. So any trigger will ONLY updates the updatepanel. But any other control that causes a postback will also update the updatepanel unless you put that control in a separate updatepanel with updatemode conditional. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 29, 2013 1:22 AM
  • User555306248 posted

    How UpdatePanel Controls Are Refreshed

    The following list describes the property settings of the UpdatePanel control that determine when a panel's content is updated during partial-page rendering.

    • If the UpdateMode property is set to Always, the UpdatePanel control’s content is updated on every postback that originates from anywhere on the page. This includes asynchronous postbacks from controls that are inside other UpdatePanel controls, and postbacks from controls that are not inside UpdatePanel controls.

    • If the UpdateMode property is set to Conditional, the UpdatePanel control’s content is updated when one of the following is true:

      • When the postback is caused by a trigger for that UpdatePanel control.

      • When you explicitly call the UpdatePanel control's Update method.

      • When the UpdatePanel control is nested inside another UpdatePanel control and the parent panel is updated.

      • When the ChildrenAsTriggers property is set to true and any child control of the UpdatePanel control causes a postback. Child controls of nested UpdatePanel controls do not cause an update to the outer UpdatePanel control unless they are explicitly defined as triggers for the parent panel.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, December 29, 2013 10:38 PM