ILearnable .Net

March 22, 2006

Thinking Ruby in C# 2.0 ?

Filed under: Uncategorized — andreakn @ 06:27

foreach(string chosenstring in myList.FindAll(new Predicate(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

Advertisements

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

Create a free website or blog at WordPress.com.