举例来说,如果我Page_Load方法里面,我想查询字符串数据我只是这样做:为什么HttpContext.Current需要一个类中使用,但没有一个方法
public partial class Product_Detail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string id = Request.QueryString["p"];
}
}
但如果我在课堂内,但不是在任何方法中,我必须使用:
public partial class Product_Detail : System.Web.UI.Page
{
string id = HttpContext.Current.Request.QueryString["p"];
protected void Page_Load(object sender, EventArgs e)
{
}
}
为什么?
我在这两个代码示例的页面类中,这就是为什么它让我困惑。 – 2011-02-12 03:11:14