consuela
consuela

Reputation: 29

User control communication

I have a master page that contains a user control ucStatusBar. ucStatusBar has a public method setStatus(). The method simply updates an <asp:label /> in the control with the string param passed in.

The master page content page is Summary.aspx. Summary.aspx has a user control ucNewEvent. When the form ucNewEvent is saved and either a success or fail code is returned, I am trying to update ucStatusBar with the success or fail message. I can call ucStatusBar.setStatus("success message") but i get a null reference exception at runtime when setStatus tries to set the Text property of the label b/c for some reason the <asp:label /> is null. Why would this be null? Is there a better way to achieve this?

Upvotes: 1

Views: 105

Answers (1)

JDB
JDB

Reputation: 25820

Just a guess, but I think that you are trying to set the Text property from within the Page_Load event (or some function called from within it).

ASP.NET programming is all about timing, which means you really, really need to understand the Page Life Cycle. It's possible that you are trying to access the user controls before they have finished loading.

Typically, it's best to use the Page_Load event strictly for parsing the request (Server.Request). Get the information you need, save it to class variables, then set control properties, etc, in the LoadComplete or PreRender event.

Upvotes: 1

Related Questions