Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 926665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:43:16+00:00 2026-05-15T19:43:16+00:00

My question is somewhat related to this thread: How to avoid Initialization of web

  • 0

My question is somewhat related to this thread: How to avoid Initialization of web user control inside aspx?

The UserControl should only be visible when a button is clicked.
So my usercontrol is set like this:

<example:usercontrol ID="idControl" runat="server" Visible="false" />
<asp:Button ID="showMyControl" runat="server" OnClick="ShowMyControl" /

And the usercontrol itself checks if he’s visible:

protected void Page_Load( object sender, EventArgs e ) {
    // only execute if the user control is visible
    if ( this.Visible ) {
        ...
    }
}

When I click the button I’m setting the property Visible of the usercontrol to true but when the postback occurs the Visible-property in the Page_Load of the usercontrol is still set to false.

My UserControl is probably loaded first and the Visible-property is set afterwards?
Is there an easy way to resolve this?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:43:17+00:00Added an answer on May 15, 2026 at 7:43 pm

    The Load event of your control, which is being handled by your Page_Load event handler method if I understand correctly, gets fired before the Click event of your button control. Therefore, when the Page_Load method checks this.Visible, the property has not yet been changed because the Click event handler has not yet executed.

    For this reason, I think that checking the Visible property of your control would be more appropriate in the PreRender event instead of the Load event.

    I’m guessing that you’re doing some sort of data retrieval or something that you wish to avoid if the control is not visible. Unfortunately, this sort of issue regarding the page life-cycle and the order in which events fire is sort of a common issue to deal with in ASP.Net programming.

    If all of your initialization code can easily be moved into the PreRender event, then great. Problem solved (hopefully). If not (i.e. you need something to happen before the PreRender), you may need to come up with some other mechanism to ensure that your code executes at the right time. For example, you could expose a “SetVisible” method on your control which sets the Visible property to true and then also executes whatever initialization logic is needed. The downside of this is that you can’t really guarantee that some code won’t just set your control’s Visible property to true outside of the SetVisible method that you provide.

    Another idea is to actually override the Visible property and perform your initialization logic whenever that property gets set to true.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[This question is somewhat related to this question , but the answers are not...]
Although somewhat related to this question , I have what I think is a
This question is somewhat related to this. I want to have document storage along
This is somewhat related to another question I asked: Translate GPS coordinates to location
I asked a somewhat related question but I want it to make it more
Somewhat related to my question about integers instead of decimals; my vendor provides a
This is a somewhat bizarre question. My objectives are to understand the language design
I’ve only just started using ASP.NET MVC, and I have a somewhat trivial question:
This is somewhat of a follow-up question to this question . Suppose I have
This is a somewhat low-level question. In x86 assembly there are two SSE instructions:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.