ILearnable .Net

March 3, 2006

Setting asp:Label texts too early

Filed under: Uncategorized — andreakn @ 01:53

Just discovered that if you have method calls to the code-behind (typically a protected method in the codebehind called between tags) You cannot alter The text property on labels in that method.

This probably extends to manipulating any property on any webcontrol defined in the code-front. I guess it’s just too early.

when stepping through the code The label had its original value (which obviously would have been read/instantiated in the code-front), I replaced it with a new value and when the page rendered it had turned back to the original value.

I guess this means that the code-front is read twice, before method calls in it are handled, and after. Is it just me that find this weird?

The fix to my problem was easy, I just placed the method-call in Page_Load, so no biggie, but I was stumped on it for a while

Edit: OK, so I might have missed the obvious, but of course the ViewState is copied back.. and overwrites my changes. Since ViewState is copied just before Page_Load, The earliest you can write to weeb-controls is page_load


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: