Did you know that … (Response.End versus HttpContext.Current.ApplicationInstance.CompleteRequest)

If you use the Response.End, Response.Redirect, or Server.Transfer method, a ThreadAbortException exception occurs. You can use a try-catch statement to catch this exception (of type ThreadAbortException) but having an empty catch block after my Response.End was kinda ugly.


So, rather than doing Response.End, we can call HttpContext.Current.ApplicationInstance.CompleteRequest it will causes ASP.NET to bypass all events and filtering in the HTTP pipeline chain of execution and directly execute the EndRequest event…


We never stop learning !

c# inline code reminder

Just a short reminder for inline code. While I do agree that it should be avoided as much as possible, it comes pretty handy for databindable controls or to quickly test something without recompiling everything.

So here are some quick notes :

Some code that must be executed

    void Page_Load( object sender, EventArgs e )   {  }

<% int id = int.Parse(Request["productID"]); %>

<%= writes out the code inside which means that

<%=productID %>

is equivalent to :

<% Response.Write(productID); %>

Please beware that there is no ";" at the end of your <%= … %> statement in that case.

Databinding management

<%# Eval("productID") %>

your datasource must obviously have the element selected with the right name.

Within a Repeater control, in order to create a customized link :

<asp:Hyperlink runat="server" ID="linkProduct"  NavigateUrl="product.aspx?id=<%# Eval("productID") %>" />

This is always handy to avoid dynamic user control, most of the time, a repeater with the right controls inside will do the job (and its easier to manager)