Thursday, July 8, 2010

URL Rewriting in ASP.NET

URL Rewriting in ASP.NET


Web sites often receive most of the traffic from search engines, like Google. Because of that it is very important to optimize web pages for search engines to rank higher in their search results. With better position web page receives more traffic since visitors usually look only at first page and rarely list all results. There are hundreds of factors that affect ranking. One of most important is to have keywords in URL of the page. Dynamically created sites usually don't contain keywords in URL, but use query strings, like this /ShowArticle.aspx?id=31231&category=43. This is OK if you look programming logic, pages that shows article is named ShowArticle.aspx. But it is not search engines friendly and you can't say what is on page, except that shows some article with primary key equal to some number.
   

So, the basic idea is to show to visitors and web spiders link in form like /Category-Name/Rich-Keywords-Article-Name/ , while internally execute ShowArticle.aspx?id=22342342&category=23. Another reason for translating URLs is usability. URLs with query strings are not memorable and not user friendly. Users prefer shorter URLs with meaningful keywords. One more reason for URL rewriting could be if you changing application's directory structure but you don't want to lose incoming links from other sites. In this case, everything will stay same for outside world, but your application will work differently. Also, there is some security risk if you expose your query string variables to visitors.

These are pretty common requests, and during the time a lot of different solutions are developed. The result of all methods should be the same: If you look from outside, visitor or search engine will see only a normal page with keywords in URL, but web server will execute page with query strings.
URL rewriting in web.config

This type of URL rewriting could be used only for a small number of pages. You need to rewrite every page manually in web.config's urlMappings section. This example rewrites five URLs:

<?xml version="1.0"?>
<configuration>
<urlMappings enabled="true">
 <add url="~/News.aspx"
   mappedUrl="~/Default.aspx?id=1" />
 <add url="~/Products.aspx"
   mappedUrl="~/Default.aspx?id=2" />
 <add url="~/Articles.aspx"
   mappedUrl="~/Default.aspx?id=3" />
 <add url="~/Resources.aspx"
   mappedUrl="~/Default.aspx?id=4" />
 <add url="~/About-Us.aspx"
   mappedUrl="~/Default.aspx?id=5" />
 </urlMappings>
. . .
</configuration>

As you see, although using of this method is pretty simple, you can't use it for rewriting 100 000 or more dynamic pages. URL rewriting in web.config is simple and easy, but in the same time useless in real scenario. This is new ASP.NET feature. Hopefully, URL mapping will be improved in next versions of ASP.NET to include variables, regular expressions etc. Current URL mapping allows only static links which makes it very limited in use. Notice that ASP.NET 1.1 doesn't support <urlMappings> element in web.config, this option is available from ASP.NET 2.0.
URL rewriting in Global.asax

URL rewriting using Global.asax file is also very simple, but in the same time pretty useful too. You need to use Application_BeginRequest event. Inside procedure, use Context.RewritePath method to specify which URL will execute in behind. Here is a code:

[ C# ]

void Application_BeginRequest(object sender, EventArgs e)
{
 // Get current path
 string CurrentPath = Request.Path.ToLower();

 // Now we'll try to  rewrite URL in form of example format:
 //  /Articles/Article-Keywords-Rich-Slug/
 // Check if URL  needs rewriting, other URLs will be ignored
 if (CurrentPath.StartsWith("/articles/"))
 {
   // I will use  simple string manipulation, but depending
   // of your case,  you can use regular expressions instead
   // Remove /  character from start and beginning
   CurrentPath = CurrentPath.Trim("/");
   string ArticleSlug = CurrentPath.Substring(CurrentPath.IndexOf("/"));
   // Rewrite URL to  use query strings
   HttpContext MyContext = HttpContext.Current;
   MyContext.RewritePath("/Show-Article.aspx?slug=" +  ArticleSlug);
 }
}

[ VB.NET ]

<%@ Application Language="VB" %>

<script RunAt="server">

 Protected Overloads Sub Application_BeginRequest(ByVal sender As Object, ByVal e As System.EventArgs)

   ' Get current  path
   Dim CurrentPath As String = Request.Path.ToLower()

   ' Now we'll try rewrite URL in form of example format
   ' /Articles/Article-Keywords-Rich-Slug/
   ' Check if URL needs rewriting, other URLs will be ignored
   If CurrentPath.StartsWith("/articles/") Then
      ' I will use  simple string manipulation, but depending
      ' of your case,  you can use regular expressions instead
      ' Remove / character from start and beginning
      CurrentPath = CurrentPath.Trim("/")
      Dim ArticleSlug As String = CurrentPath.Substring(CurrentPath.IndexOf("/"))
      ' Rewrite URL to use query strings
      Dim MyContext As HttpContext = HttpContext.Current
      MyContext.RewritePath("/Show-Article.aspx?slug=" &  ArticleSlug)
   End If
 End Sub
</script>

This example uses slug as query string parameter. Because of that, slug needs to be unique for every page. If you find this difficult or not appropriate for your case, another option is to add ID at the end of the URL, then extract it from string to some ArticleID variable, and then rewrite path to something like RealPath = "/Show-Article.aspx?id=" + ArticleID.

By using Application_BeginRequest method you can experience some difficulties, depending of which version of IIS you use and what are settings used. In some scenarios IIS will not activate ASP.NET if page not exists. In that case instead of URL rewriting you'll see just 404 Not Found error. Solution is to set IIS to inform ASP.NET about web request even if file not exists. On the web site level, click Configuration button for application settings and find "Check if file exists" check box. If you are on shared hosting and provider would not change settings, you still can use some of next methods like ISAPI or ASP.NET Routing.
URL rewriting with HttpModule

URL rewriting with HttpModule was one of the best methods to implement URL rewriting until Routing is introduced. HttpModules are reusable and can be configured easily. To learn generally about HttpModules and how to create one check How To Create Your Own Http Module tutorial.

To create HttpModule, open Visual Studio and start new project of type Class Library. Add reference to System.Web namespace (in Solution Explorer window, right click to References, choose Add Referenc... and add System.Web namespace from .Net tab).

Every HttpModule needs to implement IHttpModule interface, so it must have Init and Dispose methods. Change file name of the "Class1" to "UrlRewriting" and add this code:

[ C# ]

using System;
using System.Web;

namespace UrlRewriteHttpModule
{
 public class UrlRewriting : IHttpModule
 {
   /// <summary>
   /// Initialization of  HttpModule
   /// This method is required  for IHttpModule interface
   /// </summary>
   /// <param name="MyApp"></param>
   public void Init(System.Web.HttpApplication MyApp)
   {
     // Connect module function with Application's BeginRequest  event
     MyApp.BeginRequest += new System.EventHandler(Rewriting_BeginRequest);
   }

   /// <summary>
   /// Write dispose method if  you need
   /// It must be declared  because it is required by
   /// IhttpModule interface
   /// </summary>
   public void Dispose()
   {
     // Our example is simple and we don't need to do
     // anything here
   }

   /// <summary>
   /// Here we'll actually  rewrite URLs
   /// </summary>
   /// <param name="sender"></param>
   /// <param name="args"></param>
   public void Rewriting_BeginRequest(object sender, System.EventArgs args)
   {
     // Get reference of current web application
     HttpApplication MyApp = (HttpApplication)sender;
     // Get original page address
     string MyOldPath = MyApp.Request.Path;
     // Do some simple or more complex processing
     if (MyOldPath == "/Products/")
     {
       // And finally rewrite URL
       MyApp.Context.RewritePath("/ShowCategory.aspx?name=Products");
     }
   }
 }
}

[ VB.NET ]

Imports System
Imports System.Web

Namespace UrlRewriteHttpModule

 Public Class UrlRewriting
   Implements IHttpModule

   ''' <summary>
   ''' Initialization of HttpModule
   ''' This method is required for IHttpModule interface
   ''' </summary>
   ''' <param name="MyApp"></param>
   Public Sub Init(ByVal MyApp As HttpApplication)
     ' Connect module function with Application's BeginRequest  event
     MyApp.BeginRequest += New System.EventHandler(Rewriting_BeginRequest)
   End Sub

   ''' <summary>
   ''' Write dispose method if you need
   ''' It must be declared because it is required by
   ''' IhttpModule interface
   ''' </summary>
   Public Sub Dispose()
     ' Our example is simple and we don't need to do
     ' anything here
   End Sub

   ''' <summary>
   ''' Here we'll actually rewrite URLs
   ''' </summary>
   ''' <param name="sender"></param>
   ''' <param name="args"></param>
   Public Sub Rewriting_BeginRequest(ByVal sender As Object, ByVal args As EventArgs)
     ' Get reference of current web application
     Dim MyApp As HttpApplication = sender
     ' Get original page address
     Dim MyOldPath As String = MyApp.Request.Path
     ' Do some simple or more complex processing
     If MyOldPath = "/Products/" Then
       ' And finally rewrite URL
       MyApp.Context.RewritePath("/ShowCategory.aspx?name=Products")
     End If
   End Sub
 End Class
End Namespace

Build a project and then copy assembly to /bin folder of your web application. To make it work, you need to register it in web.config like any other HttpModule:

<system.web>
 <httpModules>
   <add type="UrlRewriteHttpModule.UrlRewriting,UrlRewriteHttpModule" name="UrlRewriteHttpModule" />
 </httpModules>
</system.web>

URL rewriting is done in module's Rewriting_BeginRequest method. First, code creates a reference of current HttpApplication and then get original URL with Request.Path or Request.URL methods. After processing of the URL, use Context.RewritePath method to rewrite URL to new value. As you see, idea of URL rewriting with Context.Rewrite path method is completely the same like in previous example of URL rewriting in Global.asax. That means that you also could experience same problems, like 404 File Not Found error. So, if that happened, you should configure IIS to call ASP.NET even if requested file not exits.

URL processing in this example is extremely simple. To make it more useful, you can create rewrite rules in web.config to add new rules without recompiling HttpModule assembly. Next logical step could be to support regular expressions to make rewrite rules more powerful.

You can enhance module on many ways, but every new feature takes time for coding and testing. Fortunately, there are two free, mature HttpModule solutions: UrlRewriter.Net and UrlRewrting.Net, with many features to make programmer's life easier.
URL rewriting with UrlRewriter.Net and UrlRewriting.Net Http Modules

Instead of building your custom HttpModule for rewriting, you can use complete HttpModule solutions. Two most popular are UrlRewriter.Net and UrlRewriting.Net. It looks like UrlRewriter.Net site is not active any more, but you can download their 1.6 version from http://www.brothersoft.com/urlrewriter.net-117841.html. Some popular ASP.NET applications, like Yet Another Forum .Net uses UrlRewriter.Net.

Second available solution is UrlRewriting.Net. Which module is better depends mostly of your preferences; technically both use same method to rewrite URLs. These modules work in medium trust (common in shared hosting), supports themes and master pages, regular expressions, post backs etc. The most important advantage of UrlRewriting.Net is easy creation of rules at run time.
How To Implement URL rewriting with UrlRewriter.Net?

To implement URL rewriting with UrlRewriter.Net follow these steps:

1. Download UrlRewriter.Net, it looks that their site is no longer active, you can still use http://www.brothersoft.com/urlrewriter.net-117841.html (source code also available).

2. Copy Intelligencia.UrlRewriter.dll to your web applicaton's /bin folder and add reference to it. 

3. Edit web.config file, register UrlRewriter in httpModules section:

<httpModules>
 <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule,  Intelligencia.UrlRewriter" />
</httpModules>
<validation validateIntegratedModeConfiguration="false" />

4. In configSections, add new section named rewriter, like this:

<configSections>
 <section name="rewriter"
 requirePermission="false"
 type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler,  Intelligencia.UrlRewriter" />
</configSections>

5.  Finally add <rewriter > section, we'll write example rewrite rule here. Place this code before </configuration>:

<rewriter>
 <rewrite url="~/Products/(.*).aspx" to="~/ShowProduct.aspx?Slug=$1"/>
</rewriter>

As you see, you can use regular expressions to get more flexible rules. In this case, requested page name is transferred to page /ShowProduct.aspx that uses query string variable.
How To Implement URL rewriting with UrlRewriting.Net?

To implement URL rewriting with UrlRewriting.Net just follow these simple steps:

1. Download product from their site, extract it somewhere on local disc and copy UrlRewritingNet.UrlRewriter.dll to /bin colder of web application.

2. Set up web.config, add new section to configSection node, and urlrewritingnew tag bellow </configsections> but before </configuration>:

<configuration>
 <configSections>
   <section name="urlrewritingnet"
      restartOnExternalChanges="true"
      requirePermission ="false"
      type="UrlRewritingNet.Configuration.UrlRewriteSection,
UrlRewritingNet.UrlRewriter" />
 </configSections>

...

<urlrewritingnet
 rewriteOnlyVirtualUrls="true"
 contextItemsPrefix="QueryString"
 defaultPage = "default.aspx"
 defaultProvider="RegEx"
 xmlns="http://www.urlrewriting.net/schemas/config/2006/07" >
</urlrewritingnet>
</configuration>

3. Register assembly as HttpModule inside httpModules section: <system.web>
<httpModules>
<add name="UrlRewriteModule"
type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
</httpModules>
</system.web>

4. Inside created urlrewritingnet node in step 3, add <rewrites > sub tag. Inside <rewrites > tag, use tag <add > to add rewrite rules. You can add as many rules as you want. Example rewrite rule could look like this:

<rewrites>
 <add name="Rewrite"  virtualUrl="^~/(.*)/Detail(.*).aspx"
   rewriteUrlParameter="ExcludeFromClientQueryString"
   destinationUrl="~/Default.aspx?language=$1&id=$2"
   ignoreCase="true" />
</rewrites>

Rewrite rule syntax is pretty simple. Notice two (.*) parts in virtualUrl attribute. These URL parts are replaced with $1 and $2 in destinationUrl attribute. Of course, you can use $3, $4 etc. if you need it. Personally, if case allows it, I prefer to add just one rule that uses article slug as parameter. If you build large application and need many rules, make your rules specific enough to avoid possible overlapping between them.

For more details about rules and using of UrlRewriting.Net, check their documentation on main site.
Postback problem with URL rewriting

As you see, it is pretty easy to implement URL rewriting. But, be aware, it is not that easy :). Web form uses real URL in action attribute. So, if visitor submits a form nice rewritten URL will be lost and in browser's address bar real URL with query strings will appear. To keep rewritten URLs after postbacks you need to change form's action attribute. You can do it in Form_Load procedure, with code like this (available in ASP.NET 3.5 SP 1 or above):

[ C# ]

protected void Page_Load(object sender, EventArgs e)
{
 form1.Action = Request.RawUrl;
}

[ VB.NET ]

Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
 form1.Action = Request.RawUrl
End Sub

You can add this code to master page to avoid repetitive code.

If your web application uses earlier version than ASP.NET 3.5 SP1, you can create a form class that inherits from standard form and change action attribute on that way.

[ C# ]

using System.Web.UI;

public class RewritingForm : HtmlForm
{
 protected override void RenderAttributes(HtmlTextWriter writer)
 {
   // write attribute name
   writer.WriteAttribute("name", this.Name);
   base.Attributes.Remove("name");

   // write attribute method
   writer.WriteAttribute("method", this.Method);
   base.Attributes.Remove("method");

   this.Attributes.Render(writer);

   // get new value of action attribute
   String action = Context.Request.RawUrl;

   // write attribute action
   if (action != null)
     writer.WriteAttribute("action", action);
       
   base.Attributes.Remove("action");

   // write id if  exists
   if (base.ID != null)
      writer.WriteAttribute("id", base.ClientID);
 }
}

[ VB.NET ]

Imports System.Web.UI

Public Class RewritingForm
 Inherits HtmlForm
 Protected Overrides Sub RenderAttributes(ByVal writer As HtmlTextWriter)
   ' write attribute name
   writer.WriteAttribute("name",  this.Name)
   base.Attributes.Remove("name")

   ' write attribute method
   writer.WriteAttribute("method", this.Method)
   base.Attributes.Remove("method")

   this.Attributes.Render(writer)

   ' get new value of action attribute
   Dim action As String = Context.Request.RawUrl

   ' write attribute action
   If action Is Not Nothing Then
     writer.WriteAttribute("action", action)
   End If

   base.Attributes.Remove("action")

   ' write id if exists
   If base.ID Is Not Nothing Then
     writer.WriteAttribute("id", base.ClientID)
   End If
 End Sub
End Class

Use this control as any other custom control instead of <form runat="server"> tag. To learn more about creating custom controls and how to place it on ASP.NET page see Custom Server Controls In ASP.NET. Another option is to use JavaScript and change form tag attribute after form is rendered. You can use jQuery to simplify this task.
Relative link problem with URL rewriting

If you use relative links (e.g. for themes, .css or .js files), these could get broken after you implement URL rewriting. If you need relative links, possible solution is to use second override of Context.RewriteUrl method and set RebaseClientPath to false:

[ C# ]

Context.RewritePath("/Real-Path-With-QueryStrings.aspx?id=23423423", false);

[ VB.NET ]

Context.RewritePath("/Real-Path-With-QueryStrings.aspx?id=23423423", false);
URL rewriting with ISAPI filter

URL rewriting in Global.asax or HttpModule works practically on the same way. There are few drawbacks when using these methods:

- by default, web server will return 404 page not found error, so you need to configure IIS to use ASP.NET even if requested resource doesn't exist
 - you can rewrite only .aspx pages. Alternative is to configure IIS to use ASP.NET for every file type, but this approach also can slow down your server and waste resources

ISAPI URL rewriting has advantage because it rewrites URL before it comes to ASP.NET. URL is rewritten as soon as request comes to IIS.     Although this solution is not free, it is worthy to check commercial solution like Helicon ISAPI_Rewrite. For only $99 you get reliable, standardized and mature solution that avoids common URL rewriting problems with Global.asax or HttpModule. ISAPI_rewrite enables control over all kinds of links, including static HTML files, images, documents, ASP.NET 1.1 or classic ASP pages etc.
Conclusion

Notice that existing incoming links to your web site will stay the same and visitors from refering sites will look for old pages, as they looked before rewriting. You need to provide permanent redirection (301) from old URL to new one. ASP.NET by default do temporal redirect (returns code 302) which splits your ranking on search engines to two URLs. Better SEO solution is to redirect permanently and send code 301. On this way, all ranking will go to your new link and old bookmarked link will still work. To find out how to implement 301 redirection check How to redirect page permanently with status code 301? tutorial.

In the past, Apache users had advantage with mod_rewrite module. Today, ASP.NET programmers have several good options for URL rewrtiing, presented in this tutorial. IIS 7 is adding new features for manipulating URLs. Also, now we get ASP.NET Routing that origin from ASP.NET MVC. More about Routing and IIS 7 URL manipulation read in some next tutorial.

Source :- http://www.beansoftware.com/ASP.NET-Tutorials/URL-Rewriting-ASP.NET.aspx

How To Reduce Page Size In ASP.NET

How To Reduce Page Size In ASP.NET


Although users today have faster Internet connection, light web pages and fast load are still popular. If your ASP.NET page is heavy, it will take some time to load and you risk that user will close browser window or go to some faster web site. Also, fast page load is respected by Google and other search engines. Pages that load fast are ranked higher in search results and because of that get more visits. With reduced page size, bandwidth costs area also reduced.


So, if small page size is so important, let's take a look on how is possible to reduce size of page without removing useful content.
Optimize images for web

Let start with basic things. If you are placed image from digital camera and just set width and height of IMG tag to smaller values that action will not resize an image (although will appear smaller on page). So, use Photoshop, Paint Shop Pro or Resize image automatically with .Net code. Photoshop has feature named "Save For Web & Devices..." which helps to optimize images, especially if you are not professional graphic designer.

Another important issue with images on web page is using of backgrund image in page layout. Try to avoid large image in background, use few smaller images or if possible one small image with background-repeat parameter. Example code that repeat small background image inside a TABLE could look like this:

<table style="background-image:url('Sunflowers.jpg');background-repeat:repeat;" width="500" height="500">
<tr>
<td>here is a table content</td>
</tr>
</table>

Notice that using a lot of small images will increase number of http requests to server that can increase time to load. The solution is using of CSS sprites. Place all background images on one image, then use CSS background-image and background-position property to display only wanted image part.
Disable, minimize or move ViewState

ViewState can grow large if you have many controls on page, especially if data controls like GridView used. The best option is to turn off ViewState or at least not use it for every control. To disable ViewState use EnableViewState="false" in Page directive, with code like this:

<%@ Page EnableViewState="false" Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

If you must use ViewState for some controls, then turn it off for other controls. Every control has a property named EnableViewState. Set this property to false for every control that not require ViewState. On this way ViewState hidden field will be smaller and page will load faster.

Another option is to move ViewState from page to Session object. This approach will reduce page size, but ViewState will take space in memory on server. If you have a lot of concurrent visitors this could be performance problem. Take care that visitor can look at the two or more pages at the same time, so ViewState of every page must be stored to separated Session object. You can try this method with code like this:

[ C# ]

protected override object LoadPageStateFromPersistenceMedium()
{
// Returns page's ViewState from Session object
return Session["ViewState-" + Request.Url.AbsolutePath];
}

protected override void SavePageStateToPersistenceMedium(object state)
{
// Saves page's ViewState to Session object
Session["ViewState-" + Request.Url.AbsolutePath] = state;
// Removes content of ViewState on page
RegisterHiddenField("__VIEWSTATE", "");
}

[ VB.NET ]

Protected Overrides Function LoadPageStateFromPersistenceMedium() As Object
' Returns page's ViewState from Session object
Return Session("ViewState-" & Request.Url.AbsolutePath)
End Function

Protected Overrides Sub SavePageStateToPersistenceMedium(ByVal state As Object)
' Saves page's ViewState to Session object
Session("ViewState-" & Request.Url.AbsolutePath) = state
' Removes content of ViewState on page
RegisterHiddenField("__VIEWSTATE", "")
End Sub

If web site has performance problems because of extensive use of Session object, notice that with LoadPageStateFromPersistenceMedium() and SavePageStateToPersistenceMedium functions you can load and save ViewState from any other source, like file system, database etc. Strategy like this will for sure reduce page size, but in the same time add additional processing to load and save ViewState from other medium so it should be used only when we can't disable ViewState or reduce it enough.
Remove inline styles to external .css file

If inline styles are moved from HTML to external .css file, pages will have smaller size. CSS file is loaded only first time when user visits web site. After that, it is stored in browser's cache and used to format every next page. Not only pages will load faster but you'll also have less maintenance work if styles are changed.

To link CSS file to HTML page use code like this in HEAD section:

<head runat="server">
<title>Page with external CSS file</title>
<link rel="stylesheet" type="text/css" href="Styles.css" />
</head>
Remove any inline JavaScript to external .js file

Like CSS styling, you can move any inline JavaScript to external .js file. On this way, JavaScript will be loaded only first time, and then cached by web browser for future use. To relate .js file to web page, add one more line in HEAD section:

<head runat="server">
<title>Page with external CSS and JS files</title>
<link rel="stylesheet" type="text/css" href="Styles.css" />
<script language="JavaScript" src="scripts/common.js"></script>
</head>
Use light page layout

A lot of nested tables will probably make your page unnecessary large. Try use DIV tags instead of tables where possible and define DIVs appearance with CSS. On this way, HTML code will be smaller. Although many designers recommend using of DIV tags only and without any table used for layout, I am not DIV purist. On my opinion, tables are still good for columns even yooyut use table for that part. I created twelve hybrid CSS/Table/DIV Page Layouts Examples. This page layout examples use both TABLE and DIVs to get light but still robust page layout.
Use HTTP compression

HTTP compression can be used to reduce number of bytes sent from server to client. If web browser supports this feature, IIS will send data compressed using GZIP. Check IIS HTTP Compression Reference to learn more.
Conclusion

Reducing page size will enable faster download but page size is not only area where you need to look. Long executing SQL query to database, or some long ASP.NET operation will make your page slow even it hasn't much HTML code or large images. To find more about this take a look at Speed Optimization in ASP.NET 2.0 Web Applications, Speed Optimization in ASP.NET 2.0 Web Applications - Part 2 and SQL Server Optimization For ASP.Net Developer tutorials.

Source :- http://www.beansoftware.com/ASP.NET-Tutorials/Reduce-Page-Size.aspx

Highlight GridView Row On MouseOver Using Javascript in Asp.net

Highlight GridView Row On MouseOver Using Javascript in Asp.net

As you knew that Gridview won't gives us the highlighting facility by default but we can achieve highlighting functionality by using simple javascript. To do that we need to use two javascript event. The one is onmouseover event which is also termed as Mouse Hover effect. The another one is onmouseout event. By using this two strong javascript events we will highlight our GridView rows. Ok now we know which javascript event we will use but how we can add these two javascript event handler with our GridView rows? The answer is simple. GridView gives us an event named RowCreated which we can use to bind
javascript event with our GridView rows. Let’s look how we can do this.

To do that first add a page in your project and give the name GridView_Row_Highlight.aspx. Now copy the following HTML markup code into the page:




<asp:GridView ID="GridView_Products" runat="server" AutoGenerateColumns="False"
Width="100%" Font-Names="tahoma" onrowcreated="GridView_Products_RowCreated">
<HeaderStyle BackColor="Red" Font-Bold="true" ForeColor="White" />
<RowStyle BackColor="Gray" />
<AlternatingRowStyle BackColor="LightGray" />
<SelectedRowStyle BackColor="Pink" ForeColor="White" Font-Bold="true" />
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:BoundField DataField="Color" HeaderText="Color" />
<asp:BoundField DataField="Size" HeaderText="Size" />
<asp:CommandField ShowSelectButton="True" />
</Columns>
</asp:GridView>



Now go to the code behind and write following code:

using System;
using System.Web.UI.WebControls;

public partial class GridView_Row_Highlight : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Bind your data in your own way
GridView_Products.DataSource = clsDbUtility.ExecuteQuery("Select * FROM Product");
GridView_Products.DataBind();
}
}
protected void GridView_Products_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// When user moves mouse over the GridView row,First save original or previous color to new attribute,
// and then change it by magenta color to highlight the gridview row.
e.Row.Attributes.Add("onmouseover","this.previous_color=this.style.backgroundColor;this.style.backgroundColor='Magenta'");

// When user leaves the mouse from the row,change the bg color
// or backgroud color to its previous or original value
e.Row.Attributes.Add("onmouseout","this.style.backgroundColor=this.previous_color;");
}
}
}

Delhi 2010 Commonwealth Games Behind Schedule

Delhi 2010 Commonwealth Games Behind Schedule


New Delhi: Zee News reports the Commonwealth Games Federation (CGF) is worried that several new venues for the 2010 Delhi Commonwealth Games are falling behind schedule.

CGF President Michael Fennel said, "we are concerned that some of the construction deadlines will not be met. But there is still time and if the new deadlines are met, that's fine".

Because of construction delays there have been cancellations of several international events that also serve as trial runs for venues being used at the October 2010 Games.

The Commonwealth shooting and boxing championships were postponed, and the world badminton championships were moved to the southern Indian city of Hyderabad.

Suresh Kalmadi, head of the organizing committee, said that all venues, except the velodrome and rugby sevens arena, would be completed by December.

"Many deadlines have been met and efforts are in hand to further enhance the efficiency in meeting laid down deadlines", he said in a statement.

Source: gamesbids

Commonwealth officials say concerned over delays to Delhi venues

Commonwealth officials say concerned over delays to Delhi venues



New Delhi: The Commonwealth Games Federation (CGF) is worried that a number of new venues for next year's multi-sports gathering in the Indian capital are falling behind schedule.
"We are concerned that some of the construction deadlines will not be met," CGF president Michael Funnel told CNN-IBN news channel on Friday following a meeting of the Games' coordination committee.

"But there is still time and if the new deadlines are met, that's fine," he added. Delays in construction have led to the cancellation of several international events that also serve as trail runs for venues being used at the October 2010 Games.

The Commonwealth shooting and boxing championships were postponed, while the world badminton championships were moved to the southern Indian city of Hyderabad.

Organizing chairman Suresh Kalmadi assured the committee that all venues, expect the velodrome and rugby sevens arena, would be completed by December.

"Many deadlines have been met and efforts are in hand to further enhance the efficiency in meeting laid down deadlines," Kalmadi said in a statement.


Source: af.reuters

Mahindra to add 1,000 more holiday homes

Mahindra to add 1,000 more holiday homes


New Delhi: Eying the growing domestic tourist sector, Mahindra Holidays and Resorts, a part of Mahindra group, said it will be adding 1,000 more holiday homes under its newly-launched Homestays brand.

"India is not a place to see but to experience. Homestays is a new concept which allows tourists to stay in Indian homes instead of hotels, allowing them to experience a little more of the 'real' India," company managing director Ramesh Ramanathan told reporters.

Under the scheme, tourists will stay with families in their homes in select locations, where they can get a peek into the cultural traditions, history and everyday life of the hosts and enjoy local home-cooked food.

The tariff starts from Rs.1,200 that includes taxes and breakfast, with the average rate being Rs.2,500.

At present, Mahindra Homestays has around 50 family properties in 10 states including Delhi, Rajasthan, Kerala and Himachal Pradesh.

The hotel brand was launched last July mainly targeting foreign tourists. But now the company is also looking at the middle class domestic tourists.

"Our target is to bring 120 Homestays units under our brand by the end of current year and 1,000 in the next five years," Ramnathan said, adding that 80 percent of the revenue earned would go to home owners.

"We have already signed agreements with the Kerala tourism department and are in talks with Tamil Nadu, West Bengal, Uttarakhand and Delhi."

The company is also eying the 2010 Delhi Commonwealth Games and has roped in eight Homestays partner in the capital and adjoining areas, he added.

Source: economictimes

Delhi toes Beijing line, eco-friendly buses to ferry Games athletes

Delhi toes Beijing line, eco-friendly buses to ferry Games athletes


New Delhi: Taking inspiration from the Beijing Olympics held last year, the Delhi government, too, is keen to display its commitment towards the conservation of environment to the world. It plans to introduce ‘hybrid’ electric buses during the Commonwealth Games to be held in October 2010.

These hybrid buses will run on CNG and electric energy, and the government plans to station them at all 11 Games venues to transport athletes and spectators. It may also possibly give joyrides to inquisitive visitors.

While Delhi already has a huge base for a CNG-propelled public transport system and it has recently introduced subsidies on the cost of battery-operated cars and two-wheelers, Delhi Chief Secretary Rakesh Mehta said these hybrid buses would be in addition to the eco-friendly transportation structure to be provided during the Games.

“Hybrid buses were a part of the system during Beijing Olympics. Delhi, too, has a green city agenda and the event (Commonwealth Games) could be used to extend our commitment to the cause,” he said.

Source: indianexpress

Al-Qaeda threat to Commonwealth Games, IPL and hockey World Cup

Al-Qaeda threat to Commonwealth Games, IPL and hockey World Cup


The Commonwealth Games, the Indian Premier League and the hockey World Cup were put on alert for direct attacks from al-Qaeda after the terrorist organisation's Pakistani arm made specific threats against the events.

In a rare example of a terrorist group using specific threats against sporting events to generate propaganda the 313 Brigade, an affiliate of al-Qaeda, warned that athletes and spectators attending the events in India would face "consequences". The IPL and hockey World Cup take place next month, with the Commonwealth Games scheduled for October in Delhi. In a message issued following a bomb attack on the Indian city of Pune at the weekend, Ilyas Kashmiri, the head of 313 Brigade, was quoted by Asian Times Online as saying: "We warn the international community not to send their people to the 2010 Hockey World Cup, IPL and Commonwealth Games. Nor should their people visit India – if they do, they will be responsible for the consequences."



Lalit Modi, the chairman of the IPL, last night insisted the league, which begins on March 12, would go ahead. "We are working with the Indian government on a day-to-day basis," he said. "Security is going to be very, very tight and we have discussed every eventuality." Last year the IPL was shifted out of India due to security concerns and Modi said, "we do have a back-up plan". David Faulkner, the England Hockey performance director, expects full details of security arrangements for the World Cup to be made clear by the weekend. Faulkner is waiting for the International Hockey Federation to deliver detailed plans for security at the team hotel and transportation during the tournament, which starts in New Delhi on Feb 28.



He said: "Hopefully by the weekend we will have all the necessary details and planning to hand. We've had a positive communication from the FIH and there is a briefing taking place later this week which the British High Commission is managing on our behalf." The direct threat will add to uncertainty surrounding the Delhi Commonwealth Games, which will be the largest sporting event held in the subcontinent.



Some of the world's leading athletes have already indicated they will not compete citing scheduling issues, and last year The Daily Telegraph disclosed grave reservations about security at the event. Commonwealth Games Federation chief Mike Hooper dismissed suggestions the competition should be moved to another country. "The Games will not be shifted, make no mistake, the Games in 2010 will be in Delhi, there is no Plan B," he told the Sydney Morning Herald. "From a planning and security point of view, there is nothing to my knowledge that would suggest that security planning for the Games is not on track.

The commitment is unwavering from the Indian government to deliver a safe and secure Games." Last night security experts retained by Commonwealth Games England were examining the threat. "We take the security of the English team very seriously indeed, and are working closely with a number of experts and advisers in this area," said a spokeswoman. "Any threat will be evaluated and analysed to ensure the safety of our athletes.

As things stand we have been assured it will be safe to compete and as such we intend to travel to the Games in October. We will continue to take advice and evaluate intelligence throughout the period approaching the Games." The Foreign Office said it was aware of the 313 Brigade statement, and that its advice to travellers was constantly under review. "We are monitoring developments in India closely. Our travel advice already makes clear reference to terrorism and security issues in India generally.

"We are in regular contact with UK sporting bodies ahead of events such as the Commonwealth Games in India. We will continue to work closely with the Indian authorities who are doing everything they can to ensure the safety, security and success of these forthcoming sporting events."

Source: Telegraph.co.uk

Rare Collection.. ......... ...... Einstein's father

Rare Collection.. ......... ...... Einstein's father


>Rare Collection.. ......... ...... Einstein's father

Einstein's mother

House of Einstein

Einstein's childhood photo


School class photograph in Munich , 1889. Einstein is in the front row, second from right. He did well only in mathematics and in Latin (whose logic he admired).
>Was Einstein's Brain Different?

>Of course it was-people's brains are as different as their faces. In his lifetime many wondered if there was anything especially different in Einstein's. He insisted that on his death his brain be made available for research. When Einstein died in 1955, pathologist Thomas Harvey quickly preserved the brain and made samples and sections. He reported that he could see nothing unusual. The variations were within the range of normal human variations. There the matter rested until 1999. Inspecting samples that Harvey had carefully preserved, Sandra F. Witelson and colleagues discovered that Einstein's brain lacked a particular small wrinkle (the parietal operculum) that most people have. Perhaps in compensation, other regions on each side were a bit enlarged-the inferior parietal lobes. These regions are known to have something to do with visual imagery and mathematical thinking. Thus Einstein was apparently better equipped than most people for a certain type of thinking. Yet others of his day were probably at least as well equipped-Henri Poincaré and David Hilbert, for example, were formidable visual and mathematical thinkers, both were on the trail of relativity, yet Einstein got far ahead of them. What he did with his brain depended on the nurturing of family and friends, a solid German and Swiss education, and his own bold personality.


A late bloomer: Even at the age of nine Einstein spoke hesitantly, and his parents feared that he was below average intelligence. Did he have a learning or personality disability (such as "Asperger's syndrome," a mild form of autism)? There is not enough historical evidence to say. Probably Albert was simply a thoughtful and somewhat shy child. If he had some difficulties in school, the problem was probably resistance to the authoritarian German teachers, perhaps compounded by the awkward situation of a Jewish boy in a Catholic school.

Einstein in the Bern patent office




Einstein when his light bending theory conformed



Einstein in Berlin with political figures



Einstein in a Berlin synagogue in 1930, playing his violin for a charity concert.




The Solvay Congress of 1927



E = MC^2






POSTWAR SIGNING



Einstein in his study in his home in Berlin, 1919.



Einstein at his home in Princeton, New Jersey

Result of Love Marriage!!

Result of Love Marriage!!






Result of Love Marriage!

It's ALWAYS the kids that suffer!!
His Name is Zonkey!!!!!! !

Summer Funny...

Summer Funny...















Amazing Recovery Of A Toddler

Amazing Recovery Of A Toddler



Amazing recovery of toddler with 32% burns on his face who healed with NO scars thanks to revolutionary treatment

By Luke Salked
This is the smile that Isambard Ebbutt's mother feared she would never see. 
He suffered horrific burns when he poured a cup of scalding tea over his head as a baby. 
But despite not having a single skin graft, he is almost unrecognisable nearly two years later.

Amazing recovery: The toddler after receiving a 'Bacteriosafe' technology treatment

Isambard, two, has amazed doctors by appearing to suffer no lasting damage from the accident. 
He was just 13 months old when he poured the tea over himself in September
2008.

He suffered 32 per cent burns to his face and torso, and doctors at Frenchay Hospital in Bristol feared he would suffer severe scarring or contract potentially fatal infections.
But he recovered quickly enough to return to his home in Torquay in only ten days, and his remarkable progress has continued.


Badly burned: Isambard Ebbutt in hospital after tipping a scalding cup of tea over his face


Yesterday Isambard's mother, Natalie Ebbutt, 37, who has five other children with husband Chris, said: 'It is so poignant that a cup of tea can kill but I don't think that parents are aware of the damage it can do. 
'I see adults walking around all the time with hot drinks near children. I thought he was going to die. 
'There is never a day that goes by when we don't think how lucky we are to have him in such a perfect condition and see his smiling face.'

Isambard was treated by experts from the South-West Regional Paediatric Burns Service, who have begun working with scientists from the University of Bath to create a new dressing to protect burns victims from infections. 





Having fun: Isambard plays at Frenchay Hospital in Bristol where he was treated for severe burns


The 'Bacteriosafe' technology will release antibiotics from nanocapsules triggered by the presence of bacteria which cause infectious diseases. The dressing will also change colour when the antibiotic is released to alert medics. 
Mrs Ebbutt added: 'I knew that the biggest chance of losing my child was if an infection took hold. 
'All I could do was cross my fingers and hope for the best. 
'To think now that there is a possibility of avoiding serious infection and complications with this project is amazing.'

Love story of a young man

Love story of a young man


Love story of a young man:
I used to be like this?
I met a gal?
she was like this...
Together, we were like this ?

I gave her gifts like this?

When she accepted my proposal, I was like this?

I used to talk to her all night like this
and at office used to do this...

When my friends saw my gal friend, they stared like this?

and I used to react like this?

 
BUT on Valentine Day, she gave red roses to someone else like this?


AND, I was like this?

Which later led to this.
I felt like doing this…
But rather did this . . .
I started doing this


And this
And I ended up like this…

Popular Posts