Problem while trying to set public property of user control at designtime,it happens when UpdatePanel is added in user control RRS feed

  • Question

  • In one of the user control's all other controls are placed inside an Update Panel (To get Ajax Benefit) and the user control is registered on the page.

    One public property is defined for the user control in which one of the textbox is set as read only. As this property is declared public so it appears at the design time. If we set this property at design time when page having this usercontrol is loaded it generates a run time error “Object Reference not set for textbox”. If the Update Panel is removed from the user control it works properly.


    Conclusion for this issue is that if update panel is not there in the user control, property initialization will fired after initialization of the user control but if update panel is present in the user control property initialization will be fired before initialization of the user control.


    Please refer bellow code


    //User Control Source File   UC2.ascx

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="UC2.ascx.cs"
    Inherits="NSTabDemo.UC2" %>

    <asp:UpdatePanel ID="UpdatePanel1" runat="server"  >


               <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>



    //User Control Code File

     public partial class UC2 : System.Web.UI.UserControl


               public bool testing




                       TextBox1.Enabled = value ;




    return true; 







      /// My Page Source File  Default.aspx


    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <%@ Register src="UC2.ascx" mce_src="UC2.ascx" TagName="UC2" TagPrefix="uc1" %>

    <html >

    <head runat="server">

     <title>Untitled Page</title>



      <form id="form1" runat="server">

       <aspTongue TiedcriptManager ID="ScriptManager1" runat="server"  />

              <uc1:UC2 ID="UC2_1" runat="server" testing="false"  />




    Wednesday, November 28, 2007 1:24 PM

All replies