将参数传递给 ASP .NET 页面 [英] Passing Arguments to an ASP .NET Page

查看:40
本文介绍了将参数传递给 ASP .NET 页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我最近开始使用 ASP .NET,但我对其他 .NET 框架非常熟悉.我正在处理的应用程序需要接受一个字符串索引作为命令行样式的参数.现在在我的 Page 类中,我有一个用作占位符的常量字符串.所以我的问题是两个部分:

So I've recently started working with ASP .NET but I am very familiar with other .NET frameworks. The application I'm working on needs to take in an string index as a command line-style argument. Right now in my Page class I have a const string that I'm using as a placeholder. So the question I have is a two parter:

1- 如何设置我的应用程序内部组件以接收打开页面时传入的参数?

1- How do I set up my applications innerts to recieve an argument that is passed in when the page is opened?

2- 我如何将该参数传递给页面(尤其是当我在 VS 2010 中工作时)?

2- How do I pass that argument in to the page (especially while I'm working in VS 2010)?

非常感谢!

推荐答案

您将参数传递给带有请求变量的网页(听说过 POST 或 GET?).最简单的方法是将变量附加到 url 的末尾,如下所示:

You pass arguments to web pages with request variables (ever hear of POST or GET?). The simplest way is to append the variables to the end of the url like this:

http://localhost/Default.aspx?varname=varvalue&othervarname=othervarvalue

在您的代码隐藏中,您可以使用 Request.QueryString 访问请求变量.

In your codebehind, you can access the request variables with Request.QueryString.

这篇关于将参数传递给 ASP .NET 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆