经验之谈,如有错误请指正, [email protected]
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) +"
1<br/>
");
}
}
// 这样就列举了从 webform1 传递来的 s & ss 的值
l 这里要解释一下服务器端控件
1<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页面提交数据,比如下面的例子:
//form.htm文件
1<form action="testweb.aspx" method="post" name="form1">
2<input name="txt1" type="text" width="100"/><p>
3<input name="ra_v" type="radio" value="1" width="100"/><p>
4<input name="ra_v" type="radio" value="2" width="100"/><p>
5<input name="chk_v" type="checkbox" value="1" width="100"/><p>
6<input name="chk_v" type="checkbox" value="2" width="100"/><p>
7<input type="submit"/>
8</p></p></p></p></p></form>
//testweb.aspx文件,和前者放在同一目录下
< %@Page Language="C#"%>
< %@Import Namespace="System" %>
< %@Import Namespace="System.Web" %>
1
2int loop1;
3int loop2;
4NameValueCollection coll;
5coll=Request.Form;
6String[] arr1 = coll.AllKeys;
7Response.Write("All : " + arr1.Length + "
``` ");
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
for(loop2=0;loop2
1<coll.getvalues(arr1[loop1]).length;loop2++) "=" + coll.GetValues(arr1[loop1]).GetValue (loop2) +" "th="" "the="" +="" <br="" \+="" arr1[loop1]="" loop2.tostring()="" response.write(="" {="">");
2}
3}
//运行结果是aspx页面列举出了form.htm提交过来的数据,
//我只是说
</coll.getvalues(arr1[loop1]).length;loop2++)>