Question

In my code I load a user control (uc) in the page_load event. The uc contains a button which sets a label text to the textbox value. (lblTest.Text = txtText.Text) . This works fine in the load event of my page. But when I set the loading of the uc in my Init event, the label isn't set. When I set breakpoints, I see the button event is fired, the text is set (in the code), but when the page is finished loading, the label is empty. How is that possible?

Was it helpful?

Solution

Check further down in the code to ensure that the control's text isn't being overwritten or set back to empty text. (Specifically, look further in Page_Init, functions that Page_Init invokes, and Page_Load and its invoked functions.)

If you're seeing that it's being set in the debugger to the value that you expect, then chances are pretty good that something else is changing it after the fact. That's going to be either your code, ViewState, or something else outside of your immediate control. Find that, and you should be able to do something about it.

OTHER TIPS

I dont think the control fully exists at init.

This article explains the page event cycle and may explain the issue you have: http://www.15seconds.com/issue/020102.htm

To further elaborate a bit on the other answers.

Whenever an ASP.Net site launches, five things happen in a very specific order. Read Luke's link to find out that order and plot accordingly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top