foreach(string chosenstring in myList.FindAll(new Predicate<string>(delegate(string s)
{
return s.Length>10;
})))
{
Console.WriteLine("the following string is long: " +chosenstring);
}
The preceding code will run through a list containing strings and output the strings longer than 10 words.
read it and weep
Wednesday, March 22, 2006
Friday, March 03, 2006
Setting asp:Label texts too early
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
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
Subscribe to:
Posts (Atom)