博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Asp.net中的页面跳转及post数据
阅读量:5925 次
发布时间:2019-06-19

本文共 2246 字,大约阅读时间需要 7 分钟。

1 ///  2 /// This method prepares an Html form which holds all data 3 /// in hidden field in the addetion to form submitting script. 4 ///  5 /// The destination Url to which the post and redirection 6 /// will occur, the Url can be in the same App or ouside the App. 7 /// A collection of data that 8 /// will be posted to the destination Url. 9 /// 
Returns a string representation of the Posting form.
10 ///
Samer Abu Rabie
11 12 private static String PreparePOSTForm(string url, NameValueCollection data)13 {14 //Set a name for the form15 string formID = "PostForm";16 //Build the form using the specified data to be posted.17 StringBuilder strForm = new StringBuilder();18 strForm.Append("
");21 22 foreach (string key in data)23 {24 strForm.Append("
");26 }27 28 strForm.Append("
");29 //Build the JavaScript which will do the Posting operation.30 StringBuilder strScript = new StringBuilder();31 strScript.Append("");36 //Return the form and the script concatenated.37 //(The order is important, Form then JavaScript)38 return strForm.ToString() + strScript.ToString();39 }

  对于每一个想提交的数据, 我们创建了一个隐藏域来保存它的值,我们添加了必要的脚本,通过 vPostForm.submit() 来使表单完成自动提交操作。

 

1 ///  2 /// POST data and Redirect to the specified url using the specified page. 3 ///  4 /// The page which will be the referrer page. 5 /// The destination Url to which 6 /// the post and redirection is occuring. 7 /// The data should be posted. 8 /// 
Samer Abu Rabie
9 10 public static void RedirectAndPOST(Page page, string destinationUrl, 11 NameValueCollection data)12 {13 //Prepare the Posting form14 string strForm = PreparePOSTForm(destinationUrl, data);15 //Add a literal control the specified page holding 16 //the Post Form, this is to submit the Posting form with the request.17 page.Controls.Add(new LiteralControl(strForm));18 }

 

1 NameValueCollection data = new NameValueCollection();2 data.Add("v1", "val1");3 data.Add("v2", "val2");4 HttpHelper.RedirectAndPOST(this.Page, "http://DestUrl/Default.aspx", data);

同样的这种思路还可以在js中运用

 

转载于:https://www.cnblogs.com/meiCode/p/4929878.html

你可能感兴趣的文章
stream was not readable.
查看>>
作死的自动化测试
查看>>
Eclipse开发Android的配置(包括ADT安装,SDK配置)
查看>>
PHP中redis的使用
查看>>
安装OpenLDAP步骤
查看>>
高等数学(上册)
查看>>
win7给C盘扩容
查看>>
GIT使用笔记
查看>>
groovy-闭包
查看>>
ActionScript 3 中的强制类型转换
查看>>
PHP-九个非常有用的功能[转]
查看>>
C#使用WinAPI 修改电源设置,临时禁止笔记本合上盖子时睡眠
查看>>
ubuntu apt-get常用命令的使用
查看>>
【C++程序员学 python】python split and join 分割与合并
查看>>
python环境搭建和开发工具的配置【转】
查看>>
并行任务task
查看>>
linux下内存释放问题
查看>>
【Android】Android自定义属性,attr format取值类型
查看>>
JUC之Atomic系列12大类实例讲解和原理分解
查看>>
2013年个人小结
查看>>