Tuesday, 20 May 2014

Routing

Add This in Global.asax

private void RegisterRoutes(RouteCollection collection) { RouteTable.Routes.MapPageRoute("ProductRoute", //Name of route
"Product/{Name}", //How request map the url ex Product/laptops
 "~/Product.aspx"); //Physical page that handles these requests }

RouteTable.Routes.MapPageRoute("SalesReport ", //Name of route
"SaleReport/{Name}", //How request map the url ex SaleReport/laptops
 "~/Product.aspx"); //Physical page that handles these requests }

void Application_Start(object sender, EventArgs e) { RegisterRoutes(RouteTable.Routes); }

Add this in Aspx:

<asp:HyperLink ID="Hyplaptops" runat="server" NavigateUrl='<%$RouteUrl:Name=Laptops %>' Text="Laptops"></asp:HyperLink>/>

Multiple Routing:
<asp:HyperLink ID="HypTablets" runat="server" NavigateUrl='<%$RouteUrl:Name=Tablets,routename=ProductRoute%>' Text="Laptops "></asp:HyperLink>

  <asp:HyperLink ID="HypTablets" runat="server" NavigateUrl='<%$RouteUrl:Name=Tablets,routename=SalesReport %>' Text="Laptops "></asp:HyperLink>

Get Routed data value:

 Label1.Text = Page.RouteData.Values["id"].ToString();

No comments:

Post a Comment