VS2005 ASP.Net not stopping on breakpoints

If you have IE 8 installed and your ASP.Net project won’t stop on the breakpoints you’ve set they you probably need to read this article

You basically need to add an entry to your registry to stop process growth for tabs.

I’ve copied the steps required below

1) Open RegEdit
2) Browse to HKEY_LOCALMACHINE -> SOFTWARE -> Microsoft -> Internet Explorer -> Main
3) Add a dword under this key called TabProcGrowth
4) Set TabProcGrowth to 0

XSL/T Transform from String to String

The following example transforms the supplied xml string, using XSL/T and outputs to another string

using (StringReader rdr = new StringReader(selectedLine.AdditionalInformation))
    XPathDocument doc = new XPathDocument(rdr);

    using (StringWriter writer = new StringWriter())

        transformer.Transform(doc, null, writer);
        titleLabel.Attributes.Add("onmouseover", string.Format(@"showDiv(""{0}"")", writer.ToString()));

The XSL/T loaded into the transformer variable is as follows


<table class='panelTable'></table>
<tr><td colspan='2' class='TitlePanelHeader'></td></tr>

And a sample xml string is as follows:


The result from the transformation is as follows:

Body Rides
Additional answer code
Additional answer date
Answer code
Answer date
AuthorRichard Laymon
Delivery toCompany Name, Address Line 1, AddressLine 2
Expected delivery09/08/2009
Held orders
Ordered on20/07/2009
Print runs

The code to build up the xml within the object is below, note that the values are HtmlEncoded to ensure that there are no problems in the web page.

public string AdditionalInformation
        StringBuilder builder = new StringBuilder();
        AddLabelValue(builder, "Account number", ParentPurchaseOrder.AccountNumber);
        AddLabelValue(builder, "Additional answer code", this.AdditionalAnswerCode);
        AddLabelValue(builder, "Additional answer date", 
            this.AdditionalAnswerDate.Year != 1 ? this.AdditionalAnswerDate.ToShortDateString() : "" );
        AddLabelValue(builder, "Answer code", this.AnswerCode);
        AddLabelValue(builder, "Answer date",
            this.AnswerDate.Year != 1 ? this.AnswerDate.ToShortDateString() : "");
        AddLabelValue(builder,"Author", this.Author);
        AddLabelValue(builder, "Delivery to",
            ParentPurchaseOrder.DeliveryName + ", " + ParentPurchaseOrder.Address1 + ", " +
                          ParentPurchaseOrder.Address2 + ", " +
                          ParentPurchaseOrder.Address3 + ", " +
                          ParentPurchaseOrder.Address4 + ", " +
                          ParentPurchaseOrder.Address5 + ", " +

        AddLabelValue(builder, "Expected delivery",
        AddLabelValue(builder, "Held orders", this.HeldOrders);
        AddLabelValue(builder, "Ordered on", ParentPurchaseOrder.OrderedOn.ToShortDateString());
        AddLabelValue(builder, "Print runs", this.PrintRuns);

        return builder.ToString();


private void AddLabelValue(StringBuilder builder, string label, string value)
                         label, HttpUtility.HtmlEncode(value)));

Specify file name for file from handler

When returning content to a user from a generic handler use the the AddHeader method to specify the filename

context.Response.ContentType = "text/comma-separated-values";
context.Response.AddHeader("content-disposition", "attachment; filename=PrinterDirect.CSV");

?? Operator (C# Reference)

This operator allows you to supply an alternative value if the value being supplied is null. It only works on nullable datatypes but with a bit of googling came accross this article.

public int CurrentPage
        return (int)(ViewState["_CurrentPage"] ?? 0);
        this.ViewState["_CurrentPage"] = value;

The offical Microsoft article

Iterate a Dictionary

Following code iterates through each entry in a dictory

For Each keyPair As KeyValuePair(Of String, Int32) In aDepot.PostcodeCounters
    builder.Append("</td><td align=""right"">")

Creating Event Handler Signatures

In Visual Studio 2008 you’ve lost the abillity to click on the drop down in the code behind and see all the event signatures that are available but haven’t handled yet. To get the signature you are after without using the properites in the desinger you can type…


As you hit the . all methods and events should appear, pick the event you after e.g. Load

Then add type += after the event name and press TAB TAB, the event is automatically generated. ASP.Net auto wires the events with the correct name and signature so you should be able to delete the line of code that binds the event.

Check out this article for more info.

Server Control Remove Span

Normally when you write a server control, .Net automatically wraps the output with a span and the Id of the control. Depending on your CSS this can cause rendering issues. You can use the following technique to prevent the span from being rendered.

public override void RenderBeginTag(HtmlTextWriter writer)
    using (HtmlTextWriter blankOne = new HtmlTextWriter(new System.IO.StringWriter()))
public override void RenderEndTag(HtmlTextWriter writer)

It basically writes out the open tag to a new HTML Writer and therefore is not part of the final rendered HTML

SessionId – keeping it the same

If you don’t populate a value in the session of a page then the session Id will reset everytime the page is loaded.

protected void Page_PreInit(object sender, EventArgs e)
    //Need this line otherwise it resets the Session Id everytime!
    Session["keepme"] = "True";

Sort Collection

Here is a simple solution based on this article to implement a sort of a generic collection.

public ContentCollection Sort()
    List items = (List)Items;
    return this;

The Content class needs to implement IComparable

C# – IsNumeric

Use the TryParse method to determine if a value is numeric

int retNum;
if (Int32.TryParse(BookId, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out retNum))
    //Is numeric

Previous Entries