Friday, May 3, 2013

.NET Tips


How to Freeze GridView Header While Scrolling ?

This is very common problem in Web development that we need to freeze the GridView header at the time of scrolling, Here is one simple tips:

Step 1 : Create a CSS class as following

.HeaderFreez
{
position:relative ;
top:expression(this.offsetParent.scrollTop);
z-index: 10
}
Step 2 Set Gridview’s HeaderStyle CssClass as follows

CssClass="HeaderFreez" 

How to Place your reusable code into Toolbox in Visual Studio?

This is very important and small tips for all VS users. Sometimes we need a small piece of code in many places of our application or in some different application. What we do? We just copy the code from one page and paste it to the destination page.
 Visual Studio having a great feature, that you can place your code snippet inside the toolbox. For that you need to just select the code snippet and drag the selected snippet on to the general Tab.


You can rename the selected snippet, by just right clicking on snippet and click on Rename.


Now, you can use it anywhere in your application or in any VS Application by just drag and drop of the selected snippet.

How to select Block of Code in Visual Studio?

You can select line by line code very easily using mouse or keyboard. But if you want to copy some code block where you don’t to select all part of line or something like that, here is a Quick TIP For you. Press and Hold “Alt” Key, and select the code region.


Remove and Sort – Namespaces using Shortcut in Visual Studio

While dealing with maintaining coding standard like stylecop warning fix with code, most of the time we need to remove unused namespaces and sort the namespaces. We can do it easily from the context menu of the code editor. There you have three different option for “Organize Using” . Either you can Remove Unused Usings , Sort Usings or we can do it together by selecting “Remove and Sort” . Let’s see how we can make it more handy !

Even we can automatically fix this using some third party tools and addins. But it can be even very handy with in visual studio aswell, if we can set some shortcut key for them. From Tools > Option, navigate to Keyboard tab. Search for “Edit.RemoveAndSort” which command will to both remove unused usings and sort the usings, then set shortcut for the same, as I did with “Ctrl + Shift + W” , Click on “Assign” and Ok. you are done.


From next time you just need to press “Ctrl+Shift+W” to remove unused namespaces and sort them accordingly.
Even you can set the same for “Sort Usings” ( “Edit.SortUsings” ) and “Removed Unused Usings” (“Edit.RemoveUsings”) .

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 setSetFocusOnError=”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.


Now in such case where multiple validation fails at same time then first validation will get the focus.
Hope this will help you !



No comments:

Post a Comment