Reputation: 259
Is there any way that I can pass parameters to a user control/page through the path(URL) in a ASP.Net Web application(not MVC).
i.e.
http://abc.com/news/para-1/para-2
where para-1
and para-2
are parameters.
Upvotes: 5
Views: 5997
Reputation: 4367
You can use ASP.NET Friendly URLs
The ASP.NET Friendly URLs library makes it easy to enable extensionless URLs for file-based handlers (e.g. ASPX, ASHX) in ASP.NET applications.
There is a good introduction by Scott Hanselman: Introducing ASP.NET FriendlyUrls - cleaner URLs, easier Routing, and Mobile Views for ASP.NET Web Forms
Upvotes: 2
Reputation: 2855
You could try using QueryStrings.
Redirect your page like this:
Response.Redirect("Webform2.aspx?Name=" +
this.txtName.Text + "&LastName=" +
this.txtLastName.Text);
And on your new page get the values like this:
private void Page_Load(object sender, System.EventArgs e)
{
this.txtBox1.Text = Request.QueryString["Name"];
this.txtBox2.Text = Request.QueryString["LastName"];
}
Upvotes: 1
Reputation: 21969
What you are looking for is called Routing
.
If you're using .NET 4+, you can read how to implement it in a Web Forms application on MSDN.
Your rule essentially comes down to this, assuming news.aspx
is where you want to go:
routes.MapPageRoute("NewsRoute",
"News/{arg1}/{arg2}",
"~/news.aspx");
You can then proceed to access the values using any of the following methods:
Page.RouteData.Values["arg1"]
<asp:Literal ID="Literal" Text="<%$RouteValue:arg1%>" runat="server"></asp:Literal>
If you're not using .NET 4+, Scott Hanselman writes about ASP.NET FriendlyUrls, which is available in NuGet.
Upvotes: 5