Archives For May 2006

Ok, so whenever you have to copy anything in command window, you first require to set command window in mark mode (right click > Mark), and then you can select any content in window.

How about allowing command window to select any content by default without setting it in Mark mode?? You just need to make small modification in your registry.
1. Open your Registry
2. Under [HKEY_CURRENT_USERConsole], find DWORD Value with name QuickEdit.
4. Now double-click this DWORD Value to modify it, which will pop up a dialog box showing Value data as “0”.
5. Modify this value to “1” and click on “Ok” button to accept this change.

Now open command window and try selecting content by mouse. To copy the selected content, press “Enter” key. For pasting copied content, simply right click on command window, and you are done!

Disclaimer: Modifying the registry can cause serious problems that may require you to reinstall your operating system. I cannot guarantee that problems resulting from modifications to the registry can be solved. Use the information provided at your own risk.

Command Line Tricks

May 30, 2006 — 1 Comment

Sahil has posted some old tricks of using those old DOS commands. Some of the command tricks are really handy, but my favorite one will always remain the same. Its:

PROMPT $P$_$_  ???$_  O.O$_=(___)=$_   U$_$G

My Favorite DOS Command

Like his most previous posts, Scott Mitchell has written another simple and clean implementation of providing check/uncheck all functionality in GridView.

Checking All CheckBoxes in a GridView

Only thing his implementation was missing in article is placing CheckBox in header of GridView and using it to toggle rows CheckBoxes. I have made small modification in the existing code to provide this feature:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If Not Page.IsPostBack Then
Dim dirInfo As New DirectoryInfo(Request.PhysicalApplicationPath)

FileList.DataSource = dirInfo.GetFiles()
End If

'On every page visit we need to build up the CheckBoxIDs array
For Each gvr As GridViewRow In FileList.Rows
'Get a programmatic reference to the CheckBox control
Dim cb As CheckBox = CType(gvr.FindControl("RowLevelCheckBox"), CheckBox)

ClientScript.RegisterArrayDeclaration("CheckBoxIDs", String.Concat("'", cb.ClientID, "'"))

'--modified code
Dim checkAll As New CheckBox()
checkAll.Text = ""
checkAll.ID = "checkAll"
checkAll.Attributes.Add("onclick", "ChangeAllCheckBoxStates(this.checked);")

End Sub

Check/Uncheck All

NAnt is powerful scripting tool designed for developers, software process engineers, and build specialists to create an automated, repeatable process for building their developed application. Though its do assist developers to automate those same mundane tasks every evening but still most hesitate to use this tool their software developer process. NAnt provides powerful XML-based scripting and some really cool features, as Jean-Paul Boodhoo explains in his series of post “Automating Your Builds With NAnt”, which can streamline your development effort dramatically.

Automating Your Builds With NAnt – Part 1
Automating Your Builds With NAnt – Part 2
Automating Your Builds With NAnt – Part 3
Automating Your Builds With NAnt – Part 4
Automating Your Builds With NAnt – Part 5
Automating Your Builds With NAnt – Part 6
Automating Your Builds With NAnt – Part 7

Does a designer require thinking from code behind aspect of the site? Yes, as Mark Boulton suggesting in his article, designers need not to learn any code to design any site but they just need to change the way they conceive different attributes in web sites. Must read!

Designers, Engage Your Brain

K. Scott Allen has written two great articles on using Master Page in ASP.NET. Through these articles Scott tried to address some of the common problems usually faced by developer.

Master Pages In ASP.NET 2.0
Master Pages: Tips, Tricks, and Traps

Working with dynamic controls in ASP.NET is real pain for developer. First you have to create instance of control, then to configure all properties of control through code and then to look for any container control where you can drop this dynamic control. Interestingly, you also have to recreate same dynamic control on every PostBack.

Let’s start with simple example to work with dynamic control:

Label dynamicLabel = new Label();
dynamicLabel.ID = "dynamicLabel";
dynamicLabel.Width = Unit.Pixel(200);
dynamicLabel.Text = "Test Text";

This code will simply add a dynamic label in Page.

But how we can position this control to specific location in the page? That should be easy, we can use Top & Left property of this control! But if you check the properties of Label, there is no Top or Left property available. So then how we can set its location?? Well, using style attribute of control. But for that you also have to set control position style as absolute. Like this:

Label dynamicLabel = new Label();
dynamicLabel.ID = "dynamicLabel";
dynamicLabel.Width = Unit.Pixel(200);
dynamicLabel.Style.Add("POSITION", "absolute");
dynamicLabel.Style.Add("TOP", "100px");
dynamicLabel.Style.Add("LEFT", "200px");
dynamicLabel.Text = "Test Text";

Alternatively, if you already have any container control in predetermined position in the page you can add this dynamic control to that control instead of adding it to page. Dynamic control will render inside that container control.

Suppose page is already having well positioned TableRow and we want to add our dynamic control to this container then we can modify our code as:

Label dynamicLabel = new Label();
dynamicLabel.ID = "dynamicLabel";
dynamicLabel.Width = Unit.Pixel(200);
dynamicLabel.Text = "Test Text";

So far it’s working great for Label control. Let’s use same code snippet for adding TextBox control in the page. Here the modified code:

TextBox dynamicTextBox = new TextBox();
dynamicTextBox.ID = "dynamicdynamicTextBox";
dynamicTextBox.Width = Unit.Pixel(200);

When you run this code, you will going to get very weird error message:

Control ‘dynamicdynamicTextBox’ of type ‘TextBox’ must be placed inside a form tag with runat=server.

As error message clearly indicating that we can only add TextBox control inside Form tag and not in Page, we need to make modification in our code to that our dynamic control will add inside Form container instead of Page. Here is the modified code:

TextBox dynamicTextBox = new TextBox();
dynamicTextBox.ID = "dynamicdynamicTextBox";
dynamicTextBox.Style.Add("POSITION", "absolute");
dynamicTextBox.Style.Add("TOP", "100px");
dynamicTextBox.Style.Add("LEFT", "10px");
dynamicTextBox.Width = Unit.Pixel(200);

With that, we also need to at runat attribute as server for Form control. Here is the modified Form tag:

<form id="Form1" method="post">


I have added a Button control to see how dynamic control behaves with page PostBack. So if you run this code, you see that application has dynamically added TextBox control on the page. Also check the location of rendered HTML code for dynamic control on page using View Source for browser. Its inside Form1 tag.

Ok, now enter some dummy text in the rendered dynamic control on page and click on the buttonTest button. And check the how its behaving.

As I have mentioned before, if you place this dynamic creation code snippet inside the IsPostBack if condition block, dynamic controls will not going to get rendered on page after PostBack, So you have to have recreate these controls on every PostBack.

As most of the locking mechanism works in window based application, like if there is no activity by user for say 10 minutes, application automatically pops up a login dialog box to re-authenticate himself again. Whereas in web based application, being a stateless environment, its bit difficult to implement same kind of feature of auto redirecting user to login page after specific time duration.

But if we can utilize refresh attribute of meta tag, we do can achieve same kind of page flow in ASP.NET. Just put below meta snippet in header of your page.

<meta http-equiv="refresh" content=" 600;url=<%= Request.Url.AbsoluteUri %>">

First value of content attribute is number of seconds (10 minutes in above case) page will wait before redirection and next value specified the URL where page will redirect (here it will redirect to the Login.aspx page).

So test this application, minimize the wait to lesser time say 20 seconds, and run the application. Page will automatically redirect to specified page.

Alan has written a series of some good class design and implementation guidelines post.
URL: Object Design and Implementation

Rule #1: Practice Drawing Make Good Classes
Rule #2: Documation!
Rule #3: Alan’s Class Template (“ACT”)
Rule #4: Never Walk, But Fly!!!
Rule #5: Always evaluate How We Fly!
Rule #6: No Private Variable Shall Have Direct Access to the Class Public Interface
Rule #7 & #8: All about Numbers!!

Snippet Compiler

May 27, 2006 — Leave a comment

Here is a useful .NET utility if you only want to test 8 line code and without getting involve in launching that bulky VS.NET, and then creating project etc.

URL: Snippet Compiler
Download: for .NET 2.0 | for .NET 1.1

Some of the interesting features I like in Snippet Compiler:
> It minimize to the system tray of task bar.
> It can also builds WinForm EXEs, console EXEs or DLLs.
> You can compile multiple C#, VB.NET ASP.NET code.
> It can be used to store templates library as well.
> IntelliSense for static members and method
> You can also export your snippet in HTML format which can be post in your blog.

Snippet Compiler Screenshot