Archive for the ‘.NET’ Category
Two Useful, Totally Unrelated ASP.NET Topics
Here are two coding tips that I have found useful in recent days:
Explanatory text in a textbox can force the user to read directions. The textbox could say something like, “Enter search terms here separated by commas.” But when the user places the cursor inside the textbox, the instructions should clear. The standard ASP.NET textbox control does not have an OnFocus event, but the same effect may be achieved with JavaScript. Add an attribute to the textbox control during the Page_Load event:
//Note that value is set to an empty string (two single quotes) if(!Postback) { txtBox.Attributes.Add("onFocus","this.value='';"); }
Some ASP.NET controls use JScript Eval statements for databinding. In some cases, you may want to include single and double quotes in the Eval format string. Use HTML escape sequences in place of quotes:
Single quote: '
Double quote: "
Consider the following example, which uses an Eval format string:
< %# Eval("Url","this.window.href='{0}'") %>
Learning CSS for ASP.NET
Several weeks ago, I started implementing an ASP.NET 2.0 interface for a postal systems project. Although I had previous experience with n-tier web architectural design, the ASP.NET programming model was new to me, as were the constellation of languages and constructs used in modern web design. My first objective was to prototype all screens in the new interface. Initially, I thought of using Visio to layout the content, but I soon realized that it’s better to put a working “skeleton” in front of the user. The skeleton may lack tier 2 connections, but it should represent the interaction model, which includes:
- Link structure between forms.
- Dynamic, client-side content such as hover boxes and timers.
- Proposed color scheme, which is an accessibility concern for colorblind users.
- Site-wide style sheets.
std::string in the Visual Studio .NET Debugger
The VS.NET 2003 debugger evidently displays only the first 256 characters of a std::string. It terminates the string with “/H”. I could find no documentation about this behavior. Output the string to the console to ensure its validity:
std::string temp; //A long string
Console::WriteLine(new String(temp.c_str()));