Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get data from the query string in asp?

I am working on a project for an IT class where I need to pass in a value on the query string in a php page and read it into a hidden field on an ASP page.

I currently am passing the parameter fine from the php page to ASP, but I am pretty new to .NET in general. How do I get the data out of the string and into a variable in C#? For example, if the url is blah.com/upload?username=washington, how would I get "washington" and save it into a hidden field? Thanks a ton.

Jergason

Edit

I knew it would be easy. Thanks a ton.
like image 582
jergason Avatar asked Dec 01 '22 08:12

jergason


2 Answers

It seems you just want:

string username = Request.QueryString["username"];
like image 116
Noldorin Avatar answered Dec 04 '22 02:12

Noldorin


You can add a hidden field in your aspx file:

<asp:HiddenField ID="username" runat="server" />

And in your code behind populate it from the request parameter:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        username.Value = Request["username"];
    }
}
like image 40
Darin Dimitrov Avatar answered Dec 04 '22 00:12

Darin Dimitrov