页面之间传递元素的办法

在第三方页面传递参数这个思路倒是的确可以省下一些代码,至少我以前是从没这样子传过。

 1   
 2'Pass form objects submitted by a form G   
 3' ET   
 4If Request.QueryString.Count>0 Then   
 5QStr="?"   
 6For Each x In Request.QueryString   
 7QStr = QStr & x & "=" 'Write Name of Parameter   
 8QStr = QStr & Server.URLEncode(request.QueryString(x)) & "&" 'Write value of parameter   
 9Next   
10QStrSz = len(QStr)-1   
11QStr = LEFT(QStr,QStrSz)   
12else   
13QStr=""   
14End If   
15Response.Redirect("YourURL.asp" & QStr)   

The Next example shows how To build the submitted parameters from a form POST. The procedure reads all posted objects and builds a querystring parameter.

 1   
 2'Pass form objects submitted by a form G   
 3' ET   
 4If Request.form.Count>0 Then   
 5QStr="?"   
 6For Each x In Request.form   
 7QStr = QStr & x & "=" 'Write Name of Parameter   
 8QStr = QStr & Server.URLEncode(request.form(x)) & "&" 'Write value of parameter   
 9Next   
10QStrSz = len(QStr)-1   
11QStr = LEFT(QStr,QStrSz)   
12else   
13QStr=""   
14End If   
15Response.Redirect("YourURL.asp" & QStr)   

The Next code example may be used as a test ASP page To redirect to. It reads the querystring and builds a table to display the parameter name and value passed.

1@ Language=VBScript 
1<html>
2<body>   

Response.Write "<table border="1"><tr><th>Parameter</th><th>Value</th></tr>"
For Each x In Request.QueryString
Response.write "<tr><td>" &amp; x &amp; "</td><td>" 'Write Name of Parameter
Response.write Request.QueryString(x) &amp; "</td></tr>" 'Write value of parameter
Next
Response.Write "</table>"

1</body>
2</html>

当然,上面这个东西的改进版本就简洁多了,再看这个

 1   
 2If   
 3Request.QueryString.Count > 0 Then   
 4  
 5Response.Redirect("YourURL.asp?" &   
 6Request.QueryString   
 7Else   
 8If   
 9Request.Form.Count > 0 Then   
10  
11Response.Redirect("YourURL.asp?" &   
12Request.Form)   
13Else   
14  
15Response.Write("No Data Sent")   
16End   
17If   
18End If   

原来可以整个抓取的,我也是刚刚知道,不敢独吞,拿出来共享

Published At
Categories with Web编程
Tagged with
comments powered by Disqus