13 June, 2008

.Net Tips and Tricks (Part -I)

Use "App_Offline.htm" feature while updating a web site
"App_Offline.htm" feature provides a super convenient way to bring down an ASP.NET application while you updating a lot of content or making big changes to the site where you want to ensure that no users are accessing the application until all changes are done. The way app_offline.htm works is that you place this file in the root of the application. When ASP.NET sees it, it will shut-down the app-domain for the application and instead send back the contents of the app_offline.htm file in response to all new dynamic requests for the application. When you are done updating the site, just delete the file and it will come back online.

You have developed and deployed a web application on a web server. When users are making a request to the default.aspx file on the web server from their browser, they are being prompted to download the default.aspx file on their computer. What could be the problem.
Problem with aspnet_isapi.dll This behavior means that although the request is going to the IIS, it is not being executed by the asp.net worker process because IIS is not sure what to do with this file. This is because the aspnet_isapi.dll is either not present or IIS is not pointing to aspnet_isapi.dll.

Password matching regular expression
Password must be at least 4 characters, no more than 8 characters, and must include at least one upper case letter, one lower case letter, and one numeric digit. ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$

Make Window Fit any Resolution


Quickly move to matching brace in Visual Studio
Just press Ctrl+] and VS.NET will take you to the matching brace. It also will take you to the matching comment, region or quote depending on what is at the cursor now.

Incremental search in Visual Studio.
Press Ctrl+I.
Start typing the text you are searching for. (Note: you'll see the cursor jump to the first match, highlighting the current search string.)
Press Ctrl+I again to jump to the next occurrence of the search string.
To stop search, press Esc.
Advanced tip: Press Ctrl+Shift+I to search backwards

Clear all text boxes in ASP.Net


This will clear EVERYTHING from the textboxes - even if you had them pre-populated with data. A simple way to just reset it to the condition at Page_Load time, just do this in the Reset SubRoutine: Server.Transfer("YourPageName.aspx")

How to rotate a Label Text?

[asp:Label id="Label1" style="writing-mode:tb-rl" runat="server"]Label[/asp:Label]

Get Row Index with Gridview Select Button
When you autoGenerate a Select button with a Gridview, to find the RowIndex for that particular row, you can use the SelectedIndexChanged Event. Inside that event, try something like this (with a label called 'Label1':
Dim row As GridViewRow = MyGridView.SelectedRow
Dim intRow as Integer=Row.RowIndex
label1.text=intRow.ToString

Auto select Gridview Row when Editing

Let's say you have an editable Gridview, and you'd like to change the backcolor of the row you're editing, when you click the 'Edit' link for that row. It's very simple, and it's done in the Gridview's RowEditing Event.

First, you must set the SelectedIndex of the Gridview to the row you're editing:
YourGridviewID.SelectedIndex = e.NewEditIndex

And, lastly, you must change the backcolor:
YourGridviewID.SelectedRow.BackColor = Drawing.Color.Pink

You can, of course, accomplish any other row formatting options here, also.
Full code and Subroutine is here:
Protected Sub YourGridviewID_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles YourGridviewID.RowEditing

YourGridviewID.SelectedIndex = e.NewEditIndex

YourGridviewID.SelectedRow.BackColor = Drawing.Color.Pink

End Sub

No comments: