c# - ASP.NET usercontrol: check if usercontrol is visible -


My question is related to this thread:

When there is a button then only user will Only clicked should appear. So my user control is set in the following way:

  & lt; Example: User ID = "IDControl" RUNAT = "server" visible = "false" /> & Lt; Asp: button id = "showMyControl" runat = "server" OnClick = "ShowMyControl" /  

and usercontrol checks itself whether it is visible:

  Secure Zero Page_load (Object Sender, EventAgds E) {// If User Control is Visible, then Only Execute (this .view) {...}}  

When I Clicking the button I'm really installing the visible property of the usercontrol, but when the postback occurs, the view-property in User's Page_Load Also false.

My user control is probably loaded first and visual - the property is set up later?

This is the load event of your control, which is being controlled by your page_load event handler method if I If you understand correctly, the click of your button control is removed before the event, therefore, when the Page_Load method this.Visible checks, the property has not yet been changed because the click event handler has not yet Has not been executed.

For this reason, I think the probability that your visual property of control will be more appropriate in the prerendered event rather than load events.

I'm feeling that you are retrieving some types of data or something that you want to avoid if the control is not visible Unfortunately, about the page life cycle and the order, The issue is that the fire of events is a common problem for handling ASP.NET programming.

If all your initialization codes can easily be moved to the prerendered event, then the great problem solved (hopefully). If not (that is, you need to do something before the prerender), you may need to come up with some other mechanism to ensure that your code is implemented at the right time. For example, you can expose a "set vs." method on your control which sets the visible property to the right and still executes whatever initial arguments are required. The downside of this is that you can not really guarantee that some code will not set your control visual property right outside the set-up method.

Another idea is to actually override the visible property and execute its initial logic whenever that property is set to true.


Comments