简体   繁体   English

需要有关asp.net中查询字符串的帮助

[英]Need help regarding query string in asp.net

I have a page create-quote.aspx. 我有一个页面create-quote.aspx。 I want to open this page in different modes, depending on whether a querystring parameter is present or not. 我想以不同的模式打开此页面,具体取决于是否存在查询字符串参数。

My question is at which event should I check, If I have a querystring parameter or not. 我的问题是我应该检查哪个事件,如果我有一个查询字符串参数。 I think, it should be preinit, what do you say. 我想,它应该是preinit,你怎么说。

Probably the best choice is to handle them on Page_Load event: 可能最好的选择是在Page_Load事件上处理它们:

http://msdn.microsoft.com/en-us/library/ms178472.aspx#lifecycle_events http://msdn.microsoft.com/en-us/library/ms178472.aspx#lifecycle_events

You're correct. 你说的没错。 You should check the querystring in the preinit event. 您应该检查preinit事件中的查询字符串。 Before the Initialzation there is a start fase where the request en response objects are created. 在初始化之前,有一个启动fase,其中创建了响应对象的请求。

Reference: http://msdn.microsoft.com/en-us/library/ms178472.aspx 参考: http//msdn.microsoft.com/en-us/library/ms178472.aspx

I would check that in the Page_Load event something like this: 我会在Page_Load事件中检查这样的事情:

Page_Load  {

if(!Page.IsPostback) 
{


    if(Request.QueryString["id"] != null) 
     {
        // do whatever with the id value 
     }

}


}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM