Dynamically set control visibility inside ItemTemplate’s of GridView using Bind Expression

GridView TemplateField allow us to specify custom controls, multiple fields and Html using a custom template. TemplateField allows us to define a completely customized template for GridView Column. We can bind the data with in template control using binding expression. ASP.NET provides number of ways to take control over the template control. In this post I am going to discuss how we can set template control visibility based on certain condition which depends on the data source data. For example, imagine you have a link button within template field. You want to set visibility if that control based on the some value of your data source.

Continue reading

Not able to view all the running Worker Process in Visual Studio – Process Attach Window – Resolution

This might be a very simple and known to most of us, but I found  it as a query in a discussion forum of one of my article “Debug your ASP.NET Application while Hosted on IIS” which was published at Code Project . Question was regarding list of worker processes in “Process Attach window” of Visual studio. Though all the sites are running properly on IIS, still he was not able to view any processes in “Attach Process Window” while trying to attach a process from Visual Studio.

Continue reading

Use Shortcut or Context Menu for “Open Containing Folder” in Visual Studio

Open Containing Folder” is one of  the frequent used functionality to open a particular file location  in windows explore from Visual Studio IDE . How did we do that ? Yes it’s very simple, Just right click on file from files Tab and select “Open Containing Folder” from the context menu as shown in below.

1

This will open the selected item location in windows explorer. This operation by default having no keyboard shortcut. But do you know we can assign keyboard shortcut for the same or even we can customize the context menu in code editor to achieve the same as shown in below images.

4 5

Continue reading

Multipurpose Find Combo Box in Visual Studio

Most of the time we use Visual Studio find combo box (6 ) only for search contents with in the solution. But the find combo box is something more than what we  know. We can use the find combo box in different purpose like create file, open files, create project, print, open watch windows etc. As for example you can close all the open files by just typing  “>CloseAll”  with in find combo box followed by a  “Enter”.  Fundamentally we can execute all the commands from Find Combo box which are available from Visual Studio Command Window. Like Command Window,  In Combo Box, if you type “>” and aliases and press enter result will be the same.

Continue reading

What is the difference between Web Farm and Web Garden ?

I have been asked this question many times by different readers of my blog. They wanted to know about the fundamentals of Web Farms and Web Garden . In this blog post  I am going to explain the what is the exact difference between web farm and web garden, what are the advantages and disadvantages of using them. I have also described how to create web garden in different version of IIS.

Overview :

Visual Studio having its own integrated ASP.NET engine which is used to run the ASP.NET Web application from Visual Studio. ASP.NET Development Server  is responsible for execute all the request and response from client. Now after the end of development, when you want to host the site on some server to allow other peoples to access, concept of web servers comes in between.  A web server is responsible for  provide the response for all the requests that are coming from clients. Below diagram showing the typical deployment structure of a ASP.NET Web application with a single IIS.

2 Clients request for resources and IIS Process the request and send back to clients. If you want to know more details on How IIS Process the request please read one of my article over “How IIS Process ASP.NET Request ?” .

Web Farm :

This is the case, where you have only one web server and multiple clients requesting for the resources from the same server. But when there is huge numbers of  incoming traffic for your web sites, one standalone server is not sufficient to process the request.  You may need to use multiple server to host the application and divide the traffic among them.  This is called “Web Farm” . So when you are hosting your single web site on multiple web server over load balancer called “Web Farm”. Below diagram showing the over all representation of Web Farms.

 Web Farms

Continue reading

How to remove Hyperlink from ASP.NET TreeView Control Nodes ?

ASP.NET Tree view control rendered as HTML Table – TR –TD  elements. Each of the node are been represented as hyperlinks. Some times you may not want that fields as hyperlink and you want to be those nodes should be represent as static text. Many of the developer did the same using  font style or css style change of the node, but it can be done very easily.  In this small blog  post I am going to describe how you can represent a tree view node as simple text instead of hyperlink.

This can be done very easily using Tree Nodes, SelectionAction properties. SelectionAction having 4 different values, they are.

3

Select is the default option which marked node as hyperlinked and on selection of the node, it raised SelectedNodeChanged event.  For Expand Option, TreeNodeExpanded event will be raised while expanding the node. “SelectExpand” raised both the SelectedNodeChanged and  TreeNodeExpanded  events. Now if you don’t want to make the node as simple text, just change the SelectionAction properties to “None”.

1

Continue reading

Use “Obsolete” attributes to indicate Obsolete Methods

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.

1

Continue reading

How to suppress compiler warning using #pragma warning directives in Visual Studio

Sometimes during development you may need to avoid the unnecessary compiler warnings to show in warning window. Though it’s not recommended to suppress the warning explicitly, but during some debugging and analysis of code you may want to hide them for time being. In this post I have explained how you can hide the unwanted warning explicitly by specifying the warning number.

To suppress the warning you need to use #pragma warning directives in your code. Below is the syntax for the same.

#pragma warning disable <warning-Numbers>

[Line of Code ]

Let’s consider you are having the below code block and you want to suppress the warning messages.

1

If you are going to build the above code, you will find the below warning messages.

2

Continue reading

How to set automatically focus on ASP.NET controls when validation fails ?

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.

SetFocus

Continue reading

How to sort ASP.NET DropDownList based on DataValueField or DataTextField using LINQ?

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

Continue reading

How to pass external values with GridView HyperLinkField which are not part of your Gridview DataSource member ?

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.

GridField

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.

Continue reading

How to hide Intellisense window in Visual Studio while coding or debugging to view the code?

Here is one quick tips to hide Visual Studio Intellisense window to view the covered source code by the particular Intellisense popup. When we are working in Visual Studio and the IntelliSense window comes up, but we may want to view the code that is covered by the window.  Here you go,  Press the Ctrl key. Intellisense window becomes transparent and you can easily view your source code. Hold the Ctrl as long as you want them to be transparent.  You can do it while debugging your application or writing code.

Below is the few snaps for the the same.

1. View Code By Hiding Intellisense Window During coding

CodeMode

Continue reading