0

I have a database of some records of the users of my website, such as Name, Email, Address etc. I have created a page using ASP.net (C#), which can display the information of the user in arranged manner. I want to display that page with information when anyone click the user name from list. How can I add parameter with the page? so that I can fetch data from database using name or ID linked in the list with user name.

What I am trying to do is something like this:

example.com/userpage.aspx/XYZ

4 Answers 4

3

You can use a Query String parameter:

example.com/userpage.aspx?id=XYZ

Access the id on the server using the QueryString Collection on the Request object:

string id = Request.QueryString["id"];
Sign up to request clarification or add additional context in comments.

Comments

2

I think you would want to use the ASP.NET Routing engine to take part of the URL and route it to a parameter.

You could set up your route to be like example.com/page.aspx?id=xyz equals example.com/page/xyz instead

Comments

1

If you are using classic ASP.NET, then you have to pass parameter to query string as Xander suggest. ASP.NET correctly parses parameters after ? and you can access them via Request["parameterName"].

But if you want "user friendly url" like you posted, then you need some mechanism to rewrite user friendly url to system url.

  • First of all, you can use IIS7 Url Rewrite module or any 3d party Url Rewrite module. Usually it is based on regular expressions and can rewrite url /Users/XYZ to /Users.aspx?name=XYZ

  • Also you can use relatively new technology ASP.NET Rounting Engine like Ryan suggested.

  • If your url scheme is complex and you can not describe it with regular expressions, then you may write your own HTTP Module and perform some custom rewrite rules.

If your Users.aspx.cs page you can read query parameter from Request["Name"], and use it value to perform some SQL query (or whatever you yse to access database)

Comments

0

If you are using GridView, you just need to attach OnRowCommand event to it and then on click of the link you can pass the name an UserID that you want to show over page.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.