Friday, October 12, 2007

To terminate the console application

To terminate the console application from the code, we can use

  • Environment.Exit
  • Process.Kill

Response.Redirect inside Try Catch block throws ThreadAbortException

Making use of the Response.Redirect inside the Try / Catch block, always throws ThreadAbortException.
As a workaround we can try using Response.Redirect(URL, False) in such cases (during unavoidable situations).

Check if a column exists in a DataTable

To check if a column exists in a DataTable / DataRow
From DataTable:
From DataRow:

Avoid multiple submits during the ongoing postback

To Avoid multiple submits during the ongoing postbacks
Just think of an ASP.Net web page that contains a button control which initiates some time consuming task. Upon clicking that button, the page submit will be initiated. In the mean time, the button will be available for further clicking. This is common in most of the heavy duty applications / web pages.
Some sort of work around that we can immediately think against this is, disabling the button control to avoid further clicks.
To achieve this,
Need to implement some JavaScript related stuffs.
1. Create a javascript function to Find and disable the specific control(s) (Button in most of the cases). The function should return “false”.

<script type="text/javascript">
function DisableControlOnSubmit()
var buttonToBeDisabled = document.getElementById("SubmitButton");
buttonToBeDisabled.disabled = true;
return false;

2. Call the function in the onsubmit event handler of the form.

<form id="form1" runat="server" onsubmit=" DisableControlOnSubmit()">

3. In ASP.Net 2.0, set the SubmitDisabledControls attribute of the
tag to true.

<form id="form1"…………………… submitdisabledcontrols="true">

4. Set the “UseSubmitBehavior” attribute of the Submit button to “false”.

<asp:Button ……………UseSubmitBehavior="false" />

Determining the Identity

Three ways for determining the Identity
  1. Page.User.Identity
  2. System.Security.Pricipal.WindowsIdentity.GetCurrent()
  3. system.Threading.Thread.CurrentPrincipal.Identity

Strong name - Third party dll / assembly

To add strong name to a third party dll / assembly , disassemble and reassemble as follows:
ildasm / thirdparty.dll
ilasm /dll /resource=thirdparty.dll.res /out=thirdparty.dll /key=mykey.snk

ILDASM / asm.dll
ILASM /KEY=key.snk /DLL /OUTPUT=asm.dll

Ref :

Verify, dll / assembly strong named?

To verify the strong name in assembly use,
sn -v assembly

Identify the row of gridview (with checkbox column) whose checkbox checkchanged.

I'm currently working on an ASP.NET 2.0 project that uses a gridview with several checkboxes in the item templates, and we wanted to use the checkbox click event to modify appropriate data.
We need to respond to the checkbox change event, and identify which check box on which row fired the event.
Use the NamingContainer property of the accessed control and cast it to (GridViewRow).

/// <summary>
Handles the CheckedChanged event of the ItemSelectCheckBox control.
<param name="sender">The source of the event.</param>
<param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
void ItemSelectCheckBox_CheckedChanged(object sender, EventArgs e)


CheckBox checkBox = (CheckBox)sender;

GridViewRow row = (GridViewRow)checkBox.NamingContainer;




Server Application Unavailable

While trying to run an Asp.Net2.0 application, if it prompts the following error message....

Error :Server Application Unavailable
The web application you are attempting to access on this web server is currently unavailable. Please hit the "Refresh" button in your web browser to retry your request.

Administrator Note: An error message detailing the cause of this specific request failure can be found in the application event log of the web server. Please review this log entry to discover what caused this error to occur.

And the message logged in the event log is:

aspnet_wp.exe could not be started. The error code for the failure is 80004005. This error can be caused when the worker process account has insufficient rights to read the .NET Framework files. Please ensure that the .NET Framework is correctly installed and that the ACLs on the installation directory allow access to the configured account.

Solution :

Execute the aspnet_regiis -i command from the Visual Studio 2005 Command Prompt and then run the same application.

DotNet Code Attributes - Obsolescing Your Code

In C#:

[ObsoleteAttribute("This method is obsolete. Please use Retrieve(iID) instead",


public DataSet Retrieve(string sProduct)


// Code here performs the retrieve


The first parameter of the ObsoleteAttribute is the message text that the developer

will see wherever the obsolete method is used. This message text will appear in the Task

List window.

The second parameter of the ObsoleteAttribute is whether the obsolete member usage

is considered to be an error. Set the parameter to False to specify that the developer using

the method will get a warning message in the Task List window, or to True to generate a

syntax error if the method is used.

Extracts from the eBook:

Best Kept Secrets in .NET


Cycle through the clipboard ring to paste different things.

Achieve multiple paste items through Clipboard ring

It is possible to cycle through the 20 recently copied items through

Ctrl + Shift + V

Creative Commons License
This work by Tito is licensed under a Creative Commons Attribution 3.0 Unported License.