.NetForm间数据传递

2008-01-16  来源:   浏览次数 0

经验之谈,如有错误请指正,xlongjiu@hotmail.com

 

 

1.         WebForm

l         利用System.Web Namespace 中 HttpResponse Class的Redirect方法传递,HttpRequest Class的 QueryString方法接收

传递来源类webform1 中的某个方法里 使用

              Response.Redirect ("WebForm2.aspx?s=1&ss=11");

              //HttpResponse 类的方法和属性通过 ASP.NET 的内部 Response 对象公开。

       //所以Response可以使用前者的方法

传递目标类webform2 中

          private void Page_Load(object sender, System.EventArgs e)

         {

              // 在此处放置用户代码以初始化页面

              int loop1;

              NameValueCollection coll;

               

              //Load Form variables into NameValueCollection variable.

              coll=Request.QueryString ;

              //HttpRequest 类的方法和属性通过 ASP.NET 的内部 Request 对象公开。

              // Get names of all forms into a string array.

              String[] arr1 = coll.AllKeys;         

              for (loop1 = 0; loop1 < arr1.Length; loop1++)

              {

                   Response.Write(arr1[loop1] + " = " + coll.GetValues(arr1[loop1]).GetValue (0)  +"<br>");

              }

 

         }

//这样就列举了从webform1传递来的s & ss的值

 

 

l         这里要解释一下服务器端控件 <form runat=server></form> , (我觉得)在asp.Net中它只是其他服务器端控件的容器,不能再像原来的asp那样可以使用action属性向其他页面提交数据。下面是MSDN原文:

 

ms-help://MS.VSCC/MS.MSDNVS.2052/cpgenref/html/cpconhtmlformcontrol.htm

 

注意 action 属性总是设置为页本身的 URL。无法更改 action 属性;因此,只能向页本身回送。

 

当然原来在asp中经常使用的在客户端运行的form仍然可以向aspx页面提交数据,比如下面的例子:9 7 3 1 2 3 4 8 :

相关主题:

网友评论