Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Form_Load is executed on partial postback by UpdatePanel control

$
0
0
<%@ 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!

 

 


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>