locked
Form_Load is executed on partial postback by UpdatePanel control RRS feed

  • Question

  • User1791736520 posted
    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
        CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    
       
    
    </asp:Content>
    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
        <h2>
            UpdatePanel Test
        </h2>
         <br /> <br /> <br /> <br /> <br /> <br /> <br />
    
        <!-- beginning of AJAX code -->
        <asp:ScriptManager ID="ScriptManager" EnablePartialRendering = true
                       runat="server" />
    
        <div>
        <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Button1" />
                <asp:AsyncPostBackTrigger ControlID="Button2" />
                <asp:AsyncPostBackTrigger ControlID="Button3" />
            </Triggers>
    
            <ContentTemplate>
                <asp:Panel ID="Panel1" runat="server">
                    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
                    <asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click" />
                    <asp:Button ID="Button3" runat="server" Text="Button" onclick="Button3_Click" />
                    <asp:TextBox ID="TextBox1" runat="server" Height="28px" Width="667px" ></asp:TextBox>
                </asp:Panel>
            </ContentTemplate>
        </asp:UpdatePanel>
        </div>
        <!-- end of AJAX code -->
    
        <br /> <br /> <br /> 
               <asp:TextBox ID="TextBox2" runat="server" Height="18px" 
                   style="margin-bottom: 0px" Width="720px"></asp:TextBox>
        <br /> <br /> <br /> <br />
    
    </asp:Content>
    
    public partial class _Default : System.Web.UI.Page
    {
       
    
        protected void Page_Load(object sender, EventArgs e)
        {
             TextBox1.Text = "Refreshed at " +
                DateTime.Now.ToString();
    
             TextBox2.Text = "Refreshed at " +
                DateTime.Now.ToString();
        }
    
        
        protected void Button1_Click(object sender, EventArgs e)
        {
            TextBox1.Text = "Refreshed at " +
                DateTime.Now.ToString()
                + " by button 1";
    
        }
    
        protected void Button2_Click(object sender, EventArgs e)
        {
            TextBox1.Text = "Refreshed at " +
                DateTime.Now.ToString()
                 + " by button 2";
        }
    
        protected void Button3_Click(object sender, EventArgs e)
        {
            TextBox1.Text = "Refreshed at " +
                DateTime.Now.ToString()
                + " by button 3";
        }
    
       
       
    }
    



    Hi,

     

    I wrote this code as a test of the UpdatePanel control. The UpdatePanel encloses a textbox along with three buttons that act as triggers. If I run the program, the behavior is exactly as expected for a partial postback (the first textbox is updated and the second one isn't). But if I put a breakpoint in Form_Load on one of those partial postbacks, I find that Form_Load is being run. The confusing part is that Form_Load is executed, but I still get the results I expect for a partial postback.

    Any idea what I'm doing wrong?

    Thanks!

     

     

    Tuesday, September 17, 2013 3:40 PM

Answers

  • User-1360095595 posted

    You're doing nothing wrong. You just need to understand the updatepanel better. It doesn't do a partial postback. It does partial rendering. What does that mean? Good question! It means the page goes through the entire page life cycle. Only thing that's different is the rendering. Only the items within the updatepanel are updated in the page. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 17, 2013 3:45 PM

All replies

  • User-1360095595 posted

    You're doing nothing wrong. You just need to understand the updatepanel better. It doesn't do a partial postback. It does partial rendering. What does that mean? Good question! It means the page goes through the entire page life cycle. Only thing that's different is the rendering. Only the items within the updatepanel are updated in the page. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 17, 2013 3:45 PM
  • User1791736520 posted

    Thanks, I was misguided.

    Tuesday, September 17, 2013 4:03 PM
  • User1791736520 posted

    Maybe this would be a good place to ask for some guidance. My goal is to implement AJAX, not just partial rendering. Is there an AJAX control suited to the task above? Again, I have a textbox on a panel and several buttons to use as triggers. When I click a button, I want to know which one was clicked and update the textbox accordingly. I want to update just the one textbox, not the whose page.

    Is there an AJAX control suited to this task? (If so, which one or ones?)

     

    Tuesday, September 17, 2013 5:01 PM
  • User-1360095595 posted

    Since this is no longer related to your original question (UpdatePanel), I suggest you create a new thread.

    Tuesday, September 17, 2013 5:47 PM