如何从ASP中的查询字符串中获取数据? [英] How do I get data from the query string in asp?
问题描述
我正在为一个IT类的项目工作,我需要在php页面的查询字符串中传递一个值,然后将其读入ASP页面的一个隐藏字段中.
我当前正在传递该参数从php页面到ASP都很好,但是一般来说,我对.NET还是很陌生.如何从字符串中获取数据并将其放入C#中的变量中?例如,如果URL是 blah.com/upload?username=washington
,我将如何获取"washington"并将其保存到隐藏字段中?多谢.
Jergason
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
编辑
推荐答案
您可以在aspx文件中添加隐藏字段:
You can add a hidden field in your aspx file:
<asp:HiddenField ID="username" runat="server" />
然后在您的代码后面,从request参数中填充它:
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"];
}
}
这篇关于如何从ASP中的查询字符串中获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!