比如说页面为:more.aspx?friclass=kk&secclass=oo&thrclass==pp但有时不需要三个参数,
有时为:
more.aspx?friclass=kk
或:
more.aspx?friclass=kk&secclass=oo我在more页面中写下如下代码:
string a="";
a=this.Request ["friclass"];
string b="";
b=this.Request["secclass"];
string c="";
c=this.Request ["thrclass"];

if(b=="" )
{
fu();
}当这时为:more.aspx?friclass=kk时
fu()根本不执行,请问应该怎样才能灵活的在页面中根据传递的参数编写程序!

解决方案 »

  1.   

    ASP.NET页面间的传值的几种方法  
     
               ASP.NET  WEB  FORMS    给开发者提供了极好的事件驱动开发模式。然而这种简单的应用程序开发模式却给我们带来了一些小问题,举个例子,在传统的ASP应用程序中,你能够通过POST方法很容易的把一个值或多个值从一个页面传送到另一个页面,用同样的方法在ASP.NET中实现有点麻烦。在这里,我们可以通过其他方式来解决这种情形。ASP.NET为我们提供了三种方式,一种是可以通过用QueryString来传送相应的值,再一种是通过session变量来传送相应的值,还有就是通过Server.Transfer方法来实现。下面分别一一介绍:    
     
    一、使用Querystring  
    Querystring是一种非常简单的传值方式,其缺点就是会把要传送的值显示在浏览器的地址栏中,并且在此方法中不能够传递对象。如果你想传递一个安全性不是那么太重要或者是一个简单的数值时,用此方法最好不过了。下面通过一个小例子来完成传值工作,步骤如下:  
    1、创建一个web  form  
    2、在新建的web  form中放置一个button1,在放置两个TextBox1,TextBox2    
    3、为button按钮创建click事件  
    代码如下:  
    private  void  Button1_Click  
    (object  sender,  System.EventArgs  e)  
    {  
     string  url;  
     url="webform2.aspx?name="  +    
       TextBox1.Text  +  "&email="  +    
       TextBox2.Text;  
     Response.Redirect(url);  
    }  
    4、新建一个目标页面命名为webform2  
    5、在webform2中放置两个Label1,Label2  
    在webform2的Page_Load中添加如下代码:  
    private  void  Page_Load  
    (object  sender,  System.EventArgs  e)  
    {  
     Label1.Text=Request.QueryString["name"];  
     Label2.Text=Request.QueryString["email"];  
    }  
    运行,即可看到传递后的结果了。  
     
    二、使用Session变量  
     
    使用Session变量传值是一种最常见的方式了,此中方式不仅可以把值传递到下一个页面,还可以交叉传递到多个页面,直至把Session变量的值removed后,变量才会消失。举个例子看看:  
    1、创建一个web  form  
    2、在新建的web  form中放置一个button1,在放置两个TextBox1,TextBox2    
    3、为button按钮创建click事件  
    代码如下:  
    private  void  Button1_Click  
    (object  sender,  System.EventArgs  e)  
    {  
                   Session["name"]=TextBox1.Text;  
     Session["email"]=TextBox2.Text;  
     Response.Redirect("webform2.aspx");  
    }  
    4、新建一个目标页面命名为webform2  
    5、在webform2中放置两个Label1,Label2  
    在webform2的Page_Load中添加如下代码:  
    private  void  Page_Load  
    (object  sender,  System.EventArgs  e)  
    {  
     Label1.Text=Session["name"].ToString();  
     Label2.Text=Session["email"].ToString();  
     Session.Remove("name");  
     Session.Remove("email");  
    }  
    运行,即可看到传递后的结果了。  
     
    三、使用Server.Transfer  
    虽然这种方法有点复杂,但也不失为一种在页面传值的方式。  
    举个例子看看:  
    1、创建一个web  form  
    2、在新建的web  form中放置一个button1,在放置两个TextBox1,TextBox2    
    3、为button按钮创建click事件  
    代码如下:  
    private  void  Button1_Click  
    (object  sender,  System.EventArgs  e)  
    {  
     Server.Transfer("webform2.aspx");  
    }  
    4、创建过程来返回TextBox1,TextBox2控件的值代码如下:  
    public  string  Name  
    {  
     get  
     {  
       return  TextBox1.Text;  
     }  
    }  
     
    public  string  EMail  
    {  
     get  
     {  
       return  TextBox2.Text;  
     }  
    }  
    5、新建一个目标页面命名为webform2  
    6、在webform2中放置两个Label1,Label2  
    在webform2的Page_Load中添加如下代码:  
    private  void  Page_Load  
    (object  sender,  System.EventArgs  e)  
    {  
     //创建原始窗体的实例  
     WebForm1  wf1;  
     //获得实例化的句柄  
     wf1=(WebForm1)Context.Handler;  
     Label1.Text=wf1.Name;  
     Label2.Text=wf1.EMail;  
     
    }  
    运行,即可看到传递后的结果了。
      

  2.   

    在csdn上帮你找的,呵呵 借花献佛了Request.QueryString本身就是一个集合!!![Visual Basic] 
    Dim loop1, loop2 As Integer
     Dim arr1(), arr2() As String
     Dim coll As NameValueCollection
     
    ' Load Form variables into NameValueCollection variable.
    coll=Request.QueryString 
    ' Get names of all keys into a string array.
    arr1 = coll.AllKeys 
    For loop1 = 0 To arr1.GetUpperBound(0)
       Response.Write("Key: " & Server.HtmlEncode(arr1(loop1)) & "<br/>")
       ' Get all values under this key.
       arr2 = coll.GetValues(loop1)  
        For loop2 = 0 To arr2.GetUpperBound(0)
           Response.Write("Value " & CStr(loop2) & ": " & Server.HtmlEncode(arr2(loop2)) & "<br/><br/>")
        Next loop2
     Next loop1[C#] 
    int loop1, loop2;
     
    // Load NameValueCollection object.
    NameValueCollection coll=Request.QueryString; 
    // Get names of all keys into a string array.
    String[] arr1 = coll.AllKeys; 
    for (loop1 = 0; loop1 < arr1.Length; loop1++) 
    {
       Response.Write("Key: " + Server.HtmlEncode(arr1[loop1]) + "<br/>");
       String[] arr2 = coll.GetValues(arr1[loop1]);
       for (loop2 = 0; loop2 < arr2.Length; loop2++) 
       {
          Response.Write("Value " + loop2 + ": " + Server.HtmlEncode(arr2[loop2]) + "<br/>");
       }
    }[JScript] 
    var arr1, arr2 : String[]
    var coll : NameValueCollectioncoll=Request.QueryString // Load Form variables into NameValueCollection variable.
    arr1 = coll.AllKeys // Get names of all keys into a string array.
    for(var i=0; i < arr1.Length; i++){
      Response.Write("Key: " + Server.HtmlEncode(arr1[i]) + "<br/>")
      arr2 = coll.GetValues(i)  // Get all values under this key.
      for(var j=0; j < arr2.Length; j++){
          Response.Write("Value " + j + ": " + Server.HtmlEncode(arr2[j]) + "<br/><br/>")
      }
    }
      

  3.   

    只要传递的URL为 aaa.aspx?ID= xxxx
    获取页面传递参数的函数是
    HttpRequest.QueryStringint loop1, loop2;
     
    // Load NameValueCollection object.
    NameValueCollection coll=Request.QueryString; 
    // Get names of all keys into a string array.
    String[] arr1 = coll.AllKeys; 
    for (loop1 = 0; loop1 < arr1.Length; loop1++) 
    {
       Response.Write("Key: " + Server.HtmlEncode(arr1[loop1]) + "<br/>");
       String[] arr2 = coll.GetValues(arr1[loop1]);
       for (loop2 = 0; loop2 < arr2.Length; loop2++) 
       {
          Response.Write("Value " + loop2 + ": " + Server.HtmlEncode(arr2[loop2]) + "<br/>");
       }
    }