hi
refer below link
http://www.aspsnippets.com/Articles/How-to-hide-remove-ASPX-extension-in-URL-in-ASPNet.aspx
Mr muddassar put code for remove .aspx extention
here there is 3 pages...
1-Default.aspx page:
<form id="form1" runat="server">
<h1>
Home</h1>
<hr />
<a href='<%=ResolveUrl("~/Customers") %>'>View Customers</a></form>
</body>
customers.aspx:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" ItemStyle-Width="30" />
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
<asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="150" />
<asp:HyperLinkField Text="View" DataNavigateUrlFormatString="~/Customers/{0}" DataNavigateUrlFields="Id" />
</Columns>
</asp:GridView>
</form>
</body>
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Country",typeof(string)) });
dt.Rows.Add(1, "John Hammond", "United States");
dt.Rows.Add(2, "Mudassar Khan", "India");
dt.Rows.Add(3, "Suzanne Mathews", "France");
dt.Rows.Add(4, "Robert Schidner", "Russia");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
and customersdetails.aspx:
<body>
<form id="form1" runat="server">
<h1>
Customer Details</h1>
<hr />
<b>Customer Id:</b>
<asp:Label ID="lblCustomerId" runat="server" />
</form>
</body>
if (!this.IsPostBack)
{
lblCustomerId.Text = this.Page.RouteData.Values["CustomerId"].ToString();
}
and global.asax
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("Customers", "Customers", "~/Customers.aspx");
routes.MapPageRoute("CustomerDetails", "Customers/{CustomerId}", "~/CustomerDetails.aspx");
}
</script>
here in customers.aspx is gridview that when click on view it will redirect to customersdetails.aspx page and url will be like:
http://localhost:26196/Customers/1
I want exatly do same for my website that it remove .aspx extention but in customers.aspx page it do it for gridview but my data is in datalist below is code:
<asp:DataList ID="DLMostanad" runat="server" RepeatDirection="Vertical" CssClass="dLmostanad">
<ItemTemplate>
<asp:ImageButton ID="ImgContinue" runat="server" CssClass="imgconM" ImageUrl="~/Image/Main/Continue.gif" CommandArgument='<%# Eval("ID")%>' OnClick="ContinueMostanad"
OnClientClick="return SetTarget()" ForeColor="Transparent" AlternateText=""></asp:ImageButton>
</ItemTemplate>
</asp:DataList>
protected void ContinueMostanad(object sender, ImageClickEventArgs e)
{
ImageButton ImgEdit = (ImageButton)sender;
Response.Redirect("details.aspx?Id=" + ImgEdit.CommandArgument);
}
now I want do that codes for my page that when users click on button it redirect to deatail.aspx it show like this:
http://localhost:26196/Details/55
how I can do it?
Best Regards
Neda