Use “Obsolete” attributes to indicate Obsolete Methods September 3, 2010
Posted by Abhijit Jana in ASP.NET, C#, General, Tips and Tricks, Visual Studio.Tags: codeproject, How To, Visual Studio, Beginners, Tips and Tricks, Obsolete
5 comments
In this post I have explained how you can use Obsolete attributes to mark some methods which are not no longer in used or may be remove in future release of the class. During the development cycle we may need to change the name or declaration of certain methods which may be using by some other developers. In this case if you changed the name or declaration of that method, application may crash in different point of times as it’s being used by other developer in the application. In this case you can use System.ObsoleteAttributes class to generate compiler warning and indicate the method as Obsolete.
Set source view as default view for Web Pages in Visual Studio August 13, 2010
Posted by Abhijit Jana in ASP.NET, General.Tags: ASP.Net, Beginners, How To, Tips and Tricks, Visual Studio
3 comments
By default in Visual Studio for any web pages design view is the default view. Which may causes some time to load if your page is having many controls . So If you want to change the default view from Design View to Source View, just perform the following steps.
Go to “Tools” > “Options” and Navigate to “HTML Designer” Section.
How to set automatically focus on ASP.NET controls when validation fails ? August 13, 2010
Posted by Abhijit Jana in ASP.NET, General, Tips and Tricks.Tags: Beginners, How To, Set Focus Automatically, validation control
2 comments
If you are using ASP.NET Validation Control then you can use “SetFocusOnError” properties to automatically focus the control if validation fails. This will help the end user to identify the control easily.
To set focus automatically you have to set SetFocusOnError=”True”. By default it’s false. SetFocusOnError of a validation control is associated with “ControlToValidate” properties. If the validation fails, focus will automatically move to the control which is specified in ControlToValidate.
How to sort ASP.NET DropDownList based on DataValueField or DataTextField using LINQ? August 8, 2010
Posted by Abhijit Jana in .NET 4.0, ASP.NET, ASP.NET 4.0, General, Tips and Tricks.Tags: codeproject, ASP.Net, How To, Beginners, DropDownList, Sorting, LINQ, KeyValuePair, Sorting of DropDownList using LINQ
6 comments
Sorting ASP.NET Dropdown list is very common requirement for any of the web application development. To Implement this features sometimes developers used to iterate through each and every item and create a sorted list of element then reassign the same source to dropdownlist or sort the element at source itself. But this thing can be done easily using LINQ. In this post I am going describe how you can sort a ASP.NET DropDownList based on either of DataTextField or DataValueField using LINQ and list of KeyValuePair elements as DataSource.
To start with the application, let’s consider you have following List of employee data as datasource of the DropDownList.
/// <summary>
/// Create List Of Employee
/// </summary>
List<KeyValuePair<int, string>> employees = new List<KeyValuePair<int, string>>
{ new KeyValuePair<int,string>(1,"Abhijit"),
new KeyValuePair<int,string>(2,"Rahul"),
new KeyValuePair<int,string>(3,"Kunal"),
new KeyValuePair<int,string>(4,"Atul"),
new KeyValuePair<int,string>(5,"Abhishek"),
};
In the employee list collection, you have added KeyValuePair for each element, where Key is employee ID and Value is the employee name. The most interesting part of using KeyValuePair is you can bind either of Key or Value with the DropDownList as per your requirement.
Now let’s bind the DropDownList with the DataSource
How to pass external values with GridView HyperLinkField which are not part of your Gridview DataSource member ? August 3, 2010
Posted by Abhijit Jana in ASP.NET, Tips and Tricks, Visual Studio.Tags: codeproject, ASP.Net, How To, GridView, HyperLinkField, Beginners, Multiple Parameter, NavigateURL
5 comments
Few days back I have published an article “How to pass multiple values using GridView HyperLinkField ?”, where I have explained how you can pass multiple parameter with Gridview HyperLinkField using DataNavigationUrlField and DataNavigateUrlFormatString properties. In this post, I am going to explain how you can pass some external values as parameters with the same hyperlink field.
DataNavigationUrlField use only those fields as parameter which are the part of GridView DataSource. Now the problem comes when you want to pass some other variables as parameter which are not part of the DataSource. As shown in below image we are passing EmpID and ParentId as argument and this two field are the data member of GridView DataSource.
![]()
Now Say, You want pass ChildID for that particular record along with ParentID and EmpID and you want hyperlink url should be like “Default.aspx?EmpID=1&ParentID=P1&ChildID=C1”where ChildID is not part of datasource.
You can achieve this by writing code in code behind for the particular GridView. There is two events where you can overwrite the navigation url of that hyperlink field. You can use Gridview_RowDataBound or Gridview_PreRender for the same.
Identifying Worker Process (w3wp.exe) – IIS 6.0 and IIS 7.0 for Debugging ASP.NET Application July 15, 2010
Posted by Abhijit Jana in ASP.NET, IIS.Tags: ASP.Net, Debugging, IIS, WorkerProcess
19 comments
If you are debugging a ASP.NET web application which is hosted on IIS, you need to attach the particular worker process in Visual Studio to start debugging. To Attach a process we can go to Tools > Attach Process or use shortcut key Ctrl +P. The process window will show the worker process (w3wp.exe) which is currently running on IIS. You need to select the process and click on attach button to start the debugging.
Problem starts when you have multiple worker process running on IIS. If you have multiple sites hosted on IIS and each site having their own application pool then you will see the list of all worker process in the Process Attach window.

Here you need to identify the particular worker process which is associated with your application pool.
Note: Whenever we create a new Application Pool, the ID of the Application Pool is being generated and it’s registered with the HTTP.SYS (Kernel Level of IIS) . So whenever HTTP.SYS Received the request from any web application, it checks for the Application Pool and based on the application pool it send the request (more…)
How to pass ASP.NET server side array to client side and binding them with Html element? July 5, 2010
Posted by Abhijit Jana in ASP.NET, C#.Tags: codeproject, ASP.Net, javscript
9 comments
This is a very often requirement for an ASP.NET Developer to pass a sever side array to client side and access them through java Script. There are several ways to do that. But here I am describing one of the simplest steps to pass server side array to client side. In this blog post you will get to know two things, first one is the how to pass the array from server side to client side and second one is the how to bind that array to an empty “html dropdown” list.
Well, the easiest way to pass the server side array to a client side is using “RegisterArrayDeclaration” . RegisterArrayDeclaration method registers a javascript array with the System.Web.UI.Page Object. As the array object registered with the “Page” object so we can access it from javascript easily. RegisterArrayDeclaration takes array name and value of the array element as argument.
In below example, I have registered one array with name of “Skills”.
protected void Page_Load(object sender, EventArgs e)
{
// Register List of Languages
Page.ClientScript.RegisterArrayDeclaration("Skills", "'C#'");
Page.ClientScript.RegisterArrayDeclaration("Skills", "'VB.NET'");
Page.ClientScript.RegisterArrayDeclaration("Skills", "'C'");
Page.ClientScript.RegisterArrayDeclaration("Skills", "'C++'");
}
Now, what above declaration does? This is nothing but a declaration of a java script array like,
Var Skills = new Array('C#', 'VB.NET','C','C++');
These “Skills” array is now only a JavaScript array which is easily accessible by client side code. Now Let’s have a look how to access them and how to bind them in a dropdown list. (more…)
How to update controls which are outside of updatepanel during partial page rendering? June 14, 2010
Posted by Abhijit Jana in ASP.NET, General.Tags: ASP.Net
5 comments
we generally used update panel to do the partial page postback, which means to postback the controls which are only inside the update panel. For achieve this we simply call Update() method for the corresponding Update Panel. This thing is quite simple when we are trying to update any control which is inside the updatepanel itself. But, The problem may come when we want to update the controls which are outside of UpdatePanel and we need to update the same while updating then control inside updatepanel.
To make it simple. Let’s consider below scenarios. In our web page, we have Two labels (Label1 and Label2). Lable1 present inside the updatePanle and Label2 is in the outside of updatePanel. We have one Button say Button1, which is also inside the UpdatePanel. Now, our requirement is to update the Label2 while we are updating Label1 by Clicking Button1.
below is the code block for above scenarios
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode=Conditional>
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Update Button" onclick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
Now, if we click on “Button1″, it will update only the content of Label1 not Lable2.
The solutions is to use ScriptManager.RegisterDataItem() . Using RegisterDataItem() methods we can register any control with the Particular Page ScriptManager Instance. While registering we need to provide the Control name along with the data item for the control which we want to render. (more…)
How to get list of all active HttpModules in ASP.NET? June 8, 2010
Posted by Abhijit Jana in ASP.NET.Tags: ASP.Net
3 comments
Here is a quick tips to get the list of all active HTTPModules at runtime. We can get the list of all HttpModules from the web.config or from machine.config file. But, what we need to do if we want to get the list of all active HttpModules during runtime? Yes. We can easily get the details with the help of HttpApplication and HttpModuleCollection Class. If we quickly recall the IIS Process Request [One detailed Article], when a request reaches to worker Process from client browser, First of all Worker process is responsible to start and HttpRuntime by loading ISAPI filter. After that HttpRuntime load an HttpApplication object with the help of HttpApplicationFactory class. Each and every request should pass through the corresponding HTTPModule to reach to HTTPHandler, this list of module are configured by the HTTPApplication. Below is the code snippet by which we can get the list of active HttpModules.
//Get Application Instance from Current Content
HttpApplication httpApps = HttpContext.Current.ApplicationInstance;
//Get List of modules in module collections
HttpModuleCollection httpModuleCollections = httpApps.Modules;
Response.Write("Total Number Active HttpModule : " + httpModuleCollections.Count.ToString() + "</br>");
Response.Write("<b>List of Active Modules</b>" + "</br>");
foreach (string activeModule inttpModuleCollections.AllKeys)
{
Response.Write(activeModule + "</br>");
}
Below is the sample output :
This can be quite useful when we want to check if our custom created module loaded successfully or not .







