Professional Web Applications Themes

Control life cycle events not firing when control is invisible - ASP.NET Building Controls

thru my testing it seems that neither createChildControls nor onPreRender will run if the control is invisible, but Render still runs. Am i correct and why does render run if the others dont? thanks for your input~!...

  1. #1

    Default Control life cycle events not firing when control is invisible

    thru my testing it seems that neither createChildControls nor onPreRender
    will run if the control is invisible, but Render still runs. Am i correct
    and why does render run if the others dont?

    thanks for your input~!


    TS Guest

  2. #2

    Default RE: Control life cycle events not firing when control is invisible

    Hi,

    Based on my test, none of them will run if the control is invisible. Here's
    my test code:
    public partial class WebForm1 : System.Web.UI.Page
    {
    protected void Page_Init(object sender, EventArgs e) {
    MyControl p = new MyControl();
    this.form1.Controls.Add(p);
    p.Controls.Add(new TextBox());
    p.Visible = false;

    }
    }
    public class MyControl : Panel
    {
    protected override void CreateChildControls()
    {
    base.CreateChildControls();
    }
    protected override void OnPreRender(EventArgs e)
    {
    base.OnPreRender(e);
    }
    protected override void Render(HtmlTextWriter writer)
    {
    base.Render(writer);
    }
    }

    Could you double check it? If the Render runs on your side please send me a
    demo project that can reproduce this problem. My email is
    com.


    Regards,
    Allen Chen
    Microsoft Online Support

    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    com.

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project ysis and dump ysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.
    --------------------
    | From: "TS" <nospam>
    | Subject: Control life cycle events not firing when control is invisible
    | Date: Mon, 29 Sep 2008 13:10:15 -0500
    | Lines: 7
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2900.3028
    | X-RFC2646: Format=Flowed; Original
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028
    | Message-ID: <phx.gbl>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingc ontrols
    | NNTP-Posting-Host: 168.38.106.193
    | Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSF TNGP02.phx.gbl
    | Xref: TK2MSFTNGHUB02.phx.gbl
    microsoft.public.dotnet.framework.aspnet.buildingc ontrols:1121
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingc ontrols
    |
    | thru my testing it seems that neither createChildControls nor onPreRender
    | will run if the control is invisible, but Render still runs. Am i correct
    | and why does render run if the others dont?
    |
    | thanks for your input~!
    |
    |
    |

    Allen Guest

  3. #3

    Default Re: Control life cycle events not firing when control is invisible

    I see the problem. After pre-render, the control was made visible, so during
    createChildControls & onPreRender the control was invisible but when Render
    came it was visible so render ran.

    that seems a little weird behavior, seems like all or none should run.


    "Allen Chen [MSFT]" <microsoft.com> wrote in message
    news:phx.gbl... 


    TS Guest

  4. #4

    Default Re: Control life cycle events not firing when control is invisible

    Hi,

    I think it's reasonable. If we set visibility on certain stage before the
    Render the Render may run/not run. Here's the source code of the
    Control.RenderControl method and the RenderControlInternal method. Let's
    see what happens there:

    protected void RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
    {
    if (!this.flags[0x10] && !this.flags[0x200])
    {
    HttpContext context = (this.Page == null) ? null :
    this.Page._context;
    if ((context != null) && context.TraceIsEnabled)
    {
    int bufferedLength = context.Response.GetBufferedLength();
    this.RenderControlInternal(writer, adapter);
    int num2 = context.Response.GetBufferedLength();
    context.Trace.AddControlSize(this.UniqueID, num2 -
    bufferedLength);
    }
    else
    {
    this.RenderControlInternal(writer, adapter);
    }
    }
    }

    private void RenderControlInternal(HtmlTextWriter writer, ControlAdapter
    adapter)
    {
    if (adapter != null)
    {
    adapter.BeginRender(writer);
    adapter.Render(writer);
    adapter.EndRender(writer);
    }
    else
    {
    this.Render(writer);
    }
    }


    We can see if control's flags[0x10] is true the Render method will not run.
    The flags[0x10] represents the visibility of the control. To confirm this
    please try following code:

    Panel p = new Panel();
    protected void Page_Load(object sender, EventArgs e)
    {

    p.PreRender += new EventHandler(p_PreRender);
    p.Visible = false;//comment this line to test
    this.form1.Controls.Add(p);
    }
    protected override void OnSaveStateComplete(EventArgs e)
    {
    base.OnSaveStateComplete(e);
    //set a breakpoint here and check p.flags[0x10] in the watch window.
    }
    void p_PreRender(object sender, EventArgs e)
    {

    }


    Please feel free to ask if you have anything unclear.

    Regards,
    Allen Chen
    Microsoft Online Community Support

    --------------------
    | From: "TS" <nospam>
    | References: <phx.gbl>
    <phx.gbl>
    | Subject: Re: Control life cycle events not firing when control is
    invisible
    | Date: Tue, 30 Sep 2008 14:23:32 -0500
    | Lines: 105
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2900.3028
    | X-RFC2646: Format=Flowed; Original
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028
    | Message-ID: <#phx.gbl>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingc ontrols
    | NNTP-Posting-Host: 168.38.106.193
    | Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSF TNGP05.phx.gbl
    | Xref: TK2MSFTNGHUB02.phx.gbl
    microsoft.public.dotnet.framework.aspnet.buildingc ontrols:1124
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingc ontrols
    |
    | I see the problem. After pre-render, the control was made visible, so
    during
    | createChildControls & onPreRender the control was invisible but when
    Render
    | came it was visible so render ran.
    |
    | that seems a little weird behavior, seems like all or none should run.
    |
    |
    | "Allen Chen [MSFT]" <microsoft.com> wrote in message
    | news:phx.gbl...
    | > Hi,
    | >
    | > Based on my test, none of them will run if the control is invisible.
    | > Here's
    | > my test code:
    | > public partial class WebForm1 : System.Web.UI.Page
    | > {
    | > protected void Page_Init(object sender, EventArgs e) {
    | > MyControl p = new MyControl();
    | > this.form1.Controls.Add(p);
    | > p.Controls.Add(new TextBox());
    | > p.Visible = false;
    | >
    | > }
    | > }
    | > public class MyControl : Panel
    | > {
    | > protected override void CreateChildControls()
    | > {
    | > base.CreateChildControls();
    | > }
    | > protected override void OnPreRender(EventArgs e)
    | > {
    | > base.OnPreRender(e);
    | > }
    | > protected override void Render(HtmlTextWriter writer)
    | > {
    | > base.Render(writer);
    | > }
    | > }
    | >
    | > Could you double check it? If the Render runs on your side please send
    me
    | > a
    | > demo project that can reproduce this problem. My email is
    | > com.
    | >
    | >
    | > Regards,
    | > Allen Chen
    | > Microsoft Online Support
    | >
    | > Delighting our customers is our #1 priority. We welcome your comments
    and
    | > suggestions about how we can improve the support we provide to you.
    Please
    | > feel free to let my manager know what you think of the level of service
    | > provided. You can send feedback directly to my manager at:
    | > com.
    | >
    | > ==================================================
    | > Get notification to my posts through email? Please refer to
    | >
    http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
    | >
    | > Note: The MSDN Managed Newsgroup support offering is for non-urgent
    issues
    | > where an initial response from the community or a Microsoft Support
    | > Engineer within 1 business day is acceptable. Please note that each
    follow
    | > up response may take approximately 2 business days as the support
    | > professional working with you may need further investigation to reach
    the
    | > most efficient resolution. The offering is not appropriate for
    situations
    | > that require urgent, real-time or phone-based interactions or complex
    | > project ysis and dump ysis issues. Issues of this nature are
    best
    | > handled working with a dedicated Microsoft Support Engineer by
    contacting
    | > Microsoft Customer Support Services (CSS) at
    | >
    http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
    | > ==================================================
    | > This posting is provided "AS IS" with no warranties, and confers no
    | > rights.
    | > --------------------
    | > | From: "TS" <nospam>
    | > | Subject: Control life cycle events not firing when control is
    invisible
    | > | Date: Mon, 29 Sep 2008 13:10:15 -0500
    | > | Lines: 7
    | > | X-Priority: 3
    | > | X-MSMail-Priority: Normal
    | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.3028
    | > | X-RFC2646: Format=Flowed; Original
    | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028
    | > | Message-ID: <phx.gbl>
    | > | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingc ontrols
    | > | NNTP-Posting-Host: 168.38.106.193
    | > | Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSF TNGP02.phx.gbl
    | > | Xref: TK2MSFTNGHUB02.phx.gbl
    | > microsoft.public.dotnet.framework.aspnet.buildingc ontrols:1121
    | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingc ontrols
    | > |
    | > | thru my testing it seems that neither createChildControls nor
    | > onPreRender
    | > | will run if the control is invisible, but Render still runs. Am i
    | > correct
    | > | and why does render run if the others dont?
    | > |
    | > | thanks for your input~!
    | > |
    | > |
    | > |
    | >
    |
    |
    |

    Allen Guest

  5. #5

    Default Re: Control life cycle events not firing when control is invisible

    Hi,

    Have you got the expected answer?

    Regards,
    Allen Chen
    Microsoft Online Support
    --------------------
    | From: "TS" <nospam>
    | References: <phx.gbl>
    <phx.gbl>
    | Subject: Re: Control life cycle events not firing when control is
    invisible
    | Date: Tue, 30 Sep 2008 14:23:32 -0500
    | Lines: 105
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2900.3028
    | X-RFC2646: Format=Flowed; Original
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028
    | Message-ID: <#phx.gbl>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingc ontrols
    | NNTP-Posting-Host: 168.38.106.193
    | Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSF TNGP05.phx.gbl
    | Xref: TK2MSFTNGHUB02.phx.gbl
    microsoft.public.dotnet.framework.aspnet.buildingc ontrols:1124
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingc ontrols
    |
    | I see the problem. After pre-render, the control was made visible, so
    during
    | createChildControls & onPreRender the control was invisible but when
    Render
    | came it was visible so render ran.
    |
    | that seems a little weird behavior, seems like all or none should run.
    |
    |
    | "Allen Chen [MSFT]" <microsoft.com> wrote in message
    | news:phx.gbl...
    | > Hi,
    | >
    | > Based on my test, none of them will run if the control is invisible.
    | > Here's
    | > my test code:
    | > public partial class WebForm1 : System.Web.UI.Page
    | > {
    | > protected void Page_Init(object sender, EventArgs e) {
    | > MyControl p = new MyControl();
    | > this.form1.Controls.Add(p);
    | > p.Controls.Add(new TextBox());
    | > p.Visible = false;
    | >
    | > }
    | > }
    | > public class MyControl : Panel
    | > {
    | > protected override void CreateChildControls()
    | > {
    | > base.CreateChildControls();
    | > }
    | > protected override void OnPreRender(EventArgs e)
    | > {
    | > base.OnPreRender(e);
    | > }
    | > protected override void Render(HtmlTextWriter writer)
    | > {
    | > base.Render(writer);
    | > }
    | > }
    | >
    | > Could you double check it? If the Render runs on your side please send
    me
    | > a
    | > demo project that can reproduce this problem. My email is
    | > com.
    | >
    | >
    | > Regards,
    | > Allen Chen
    | > Microsoft Online Support
    | >
    | > Delighting our customers is our #1 priority. We welcome your comments
    and
    | > suggestions about how we can improve the support we provide to you.
    Please
    | > feel free to let my manager know what you think of the level of service
    | > provided. You can send feedback directly to my manager at:
    | > com.
    | >
    | > ==================================================
    | > Get notification to my posts through email? Please refer to
    | >
    http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
    | >
    | > Note: The MSDN Managed Newsgroup support offering is for non-urgent
    issues
    | > where an initial response from the community or a Microsoft Support
    | > Engineer within 1 business day is acceptable. Please note that each
    follow
    | > up response may take approximately 2 business days as the support
    | > professional working with you may need further investigation to reach
    the
    | > most efficient resolution. The offering is not appropriate for
    situations
    | > that require urgent, real-time or phone-based interactions or complex
    | > project ysis and dump ysis issues. Issues of this nature are
    best
    | > handled working with a dedicated Microsoft Support Engineer by
    contacting
    | > Microsoft Customer Support Services (CSS) at
    | >
    http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
    | > ==================================================
    | > This posting is provided "AS IS" with no warranties, and confers no
    | > rights.
    | > --------------------
    | > | From: "TS" <nospam>
    | > | Subject: Control life cycle events not firing when control is
    invisible
    | > | Date: Mon, 29 Sep 2008 13:10:15 -0500
    | > | Lines: 7
    | > | X-Priority: 3
    | > | X-MSMail-Priority: Normal
    | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.3028
    | > | X-RFC2646: Format=Flowed; Original
    | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028
    | > | Message-ID: <phx.gbl>
    | > | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingc ontrols
    | > | NNTP-Posting-Host: 168.38.106.193
    | > | Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSF TNGP02.phx.gbl
    | > | Xref: TK2MSFTNGHUB02.phx.gbl
    | > microsoft.public.dotnet.framework.aspnet.buildingc ontrols:1121
    | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingc ontrols
    | > |
    | > | thru my testing it seems that neither createChildControls nor
    | > onPreRender
    | > | will run if the control is invisible, but Render still runs. Am i
    | > correct
    | > | and why does render run if the others dont?
    | > |
    | > | thanks for your input~!
    | > |
    | > |
    | > |
    | >
    |
    |
    |

    Allen Guest

  6. #6

    Default Re: Control life cycle events not firing when control is invisible

    yes, thanks

    "Allen Chen [MSFT]" <microsoft.com> wrote in message
    news:phx.gbl... 


    TS Guest

Similar Threads

  1. Firing user control event from parent control
    By Natty Gur in forum ASP.NET Building Controls
    Replies: 2
    Last Post: February 8th, 09:09 AM
  2. Replies: 3
    Last Post: November 19th, 01:14 PM
  3. Composite Control - Event not firing in child control
    By Chris Simmons in forum ASP.NET Building Controls
    Replies: 3
    Last Post: October 28th, 09:45 PM
  4. Why is SaveViewState called twice in the Control Life Cycle?
    By Stephen Miller in forum ASP.NET Building Controls
    Replies: 0
    Last Post: December 31st, 05:54 AM
  5. Replies: 0
    Last Post: August 11th, 05:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139