Posts

Showing posts from March, 2007

"Validation of viewstate MAC failed" and "Invalid Viewstate"

This solved it for me: <%@ Page ... EnableViewStateMac="False" ViewStateEncryptionMode="Never" CompilationMode="always" EnableEventValidation="false" %>

ASP.NET Atlas

Have you tried it yet? I haven't, but I will as soon as my computer at home is running again (hardware issues ... ). That was another thing that was successfully demonstrated at the MSDN Live event yesterday. With only two extra controls (ScriptManager (global) and UpdatePanel (that you put your controls in)), you could get classic ASP controls (such as the ASP:Calendar) to refresh using Ajax instead of PostBacks. Very nice indeed. I'm going to experiement some with that as soon as I have time, and I strongly suggest that you do the same. :-)

Nag: Use StringBuilder

Yesterday, I visited MSDN Live here in Stockholm. It was very interesting (as usual). One thing I noted, however, was the reminder not to use string concatenation everywhere, but to use StringBuilder for that task. In my professional life, I have seen a lot of developer disregarding this as well. What was demonstrated at the event, was something like this: string msg = String.Empty; for(int i = 0; i < 10000; i++) { msg += i.ToString(); } Console.WriteLine(msg); Memory Allocation: About 400 Mega byte Garbage Collector: Tired. With StringBuilder: StringBuilder msg = new StringBuilder(); for(int i = 0; i < 10000; i++) { msg.Append(i.ToString()); } Console.WriteLine(msg.ToString()); Memory Allocation: About 400 Kilobyte. Garbage Collector: Happy. 400 megs or 400 kbs ... you pick ;-) Also, check this out: Writing High-Performance Managed Applications : A Primer

Find and Replace in Visual Studio 2005 using Regular Expressions

The search dialouge in Visual Studio 2005 supports Regular Expressions, which is neat. A gotcha is that it's not the regular expression you might be used to... it's a special kind ... Here's a quicky-quick tutorial: To find all entries of GetString(" variable string ") (to insert appropriate values in a resource file, for example), you do this: CTRL+SHIFT+F (find in files (to get the result as a list)) Type GetString\({:q}\) Find Options: Check Use -> Regular expressions Result Options: Find results 1 window ALT+F (Find All) Sweet. Quick explanation: "\" escapes just like in "real regex" "{" and "}" groups results (instead of "(" and ")") ":q" means "match quoted string"

Poor man's JavaScript debugger

// Hold the trace data var trace = String(); // Debug log method function debug(str) { if(trace.length > 0) trace += "\n-> "; trace += str; } // The function with errors function advancedFunction() { try { debug("advancedFunction()"); debug("doing this"); doThis(); debug("doing that"); doThat(); debug("doing other"); doOther(); } catch(ex) { debug(ex.message); alert(trace); } }

Jennifer v0.1

Image
Public release! Jennifer (the code generator), v0.1 Download Source (Boo Programming Language) Download Executable (.NET 2 Platform) Screen shot: Features: Builds ASP.NET Labels, TextBoxes and validator in a flash! Plans for next release: A saved list of control definitions so that you can create more than one control set at a time. Support for date format(s) Support for control pre- and postfixs (such as td-tags)

Dynamically creating forms in ASP.NET 2

For those of us who'd rather write code than dragging and dropping controls on a form, here comes a few pointers: 1) Always create all controls of all possible views Even if you don't want to display all dynamically created controls, you will need to create them, if you would like to benefit from ASP.NET's built-in ViewState capability. That said, you don't have to display or even populate (see point 2 below) all controls. Just create them. Then, if you don't want them after all, set their Visible flag to False . 2) Don't databind controls on postback. A common mistake when dynamically creating pages, is to attempt to databind on callback. Well,m the thing is that the control is already bound, sort of speak. The data you are trying to bind is already in the control's view state, isn't it? ;-) 3) Create a FormBuilder class Save yourself some time. Here's a sample FormBuilder (written in VB.NET becuase I get paid for it ;-)): Publ