ASP.net - Get ID from URL

13,072

Change your code to this:

protected string FormatUrl(int FriendsAccountID) { return "WebForm3.aspx?UserID=" + FriendsAccountID; }

Then you can access the UserID like this:

Request.QueryString["UserID"];

Here is a link to QueryString on MSDN.

Share:
13,072
Robert Pallin
Author by

Robert Pallin

Updated on June 04, 2022

Comments

  • Robert Pallin
    Robert Pallin almost 2 years

    I have a datalist and I'm sending the user ID of the user through the URL to another page:

    <asp:HyperLink ID="LastNameLabel" runat="server" Text='<%# Eval("LastName") %>' NavigateUrl='<%# FormatUrl( (int) Eval("FriendsAccountID")) %>' />
    

    and the function:

    protected string FormatUrl(int FriendsAccountID)
    {
        return "WebForm3.aspx?" + FriendsAccountID;
    }
    

    This works but I'm kind of a noobie and I'm not sure how get the ID once I'm on the next page. Any ideas?

  • Robert Pallin
    Robert Pallin almost 12 years
    Can that go straight into the page load WebForm3?
  • Christer Berglund
    Christer Berglund almost 12 years
    Yes. Every Webform has access to the Request object.