VB.NET中的页面重定向 [英] Page redirection in VB.NET

查看:226
本文介绍了VB.NET中的页面重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请问,如果此页面重定向可能有效吗?我无法测试它,因为项目没有编译或上传到服务器,但欢迎第二个意见。



我的HTML格式:



Can I ask, please, if this page redirection might work? I can't test it yet because the project is not compiled or uploaded to a server but a second opinion would be welcome.

I have this in my HTML form:

<asp:TextBox ID="your_name" runat="server"></asp:TextBox></p>





这个在我的aspx.vb文件中:





and this in my aspx.vb file:

Protected Sub contact_submitted_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles contact_submitted.Click

 Dim Name As String = "yourname"

 'Request.Form - extract data from form fields

  Dim yourname As String = Request.Form("your_name")

'Redirect the user after SMTP form sent

 Dim target = String.Format("~/thankyou_test.aspx?your_name={0}", Name)

 Response.Redirect(String.Format("~/thankyou_test.aspx?your_name={0}", Name), True)

 'Redirect the user

  Response.Redirect(target, True)





非常感谢



Many thanks

推荐答案

是的,尽管代码不是很简单,它仍然有效。



1.如果您回复相同的表格,可以使用

Yes, it will work although the code is not very simple.

1. If you are posting back the same form you can get the textbox value by using
your_name.Text

而不是使用Request.Form。

2.您有2次调用Response.Redirect。只有1个会起作用。 Response.Redirect表示转到此页面。

3.你将String.Format变成一个名为target的变量,但不要马上使用它。



小东西,但干净代码更容易调试和理解。

instead of using Request.Form.
2. You have 2 calls to Response.Redirect. Only 1 will work. Response.Redirect means go to this page.
3. You String.Format into a variable named target but then don't use it right away.

Minor things, but clean code is easier to debug and to understand.


这篇关于VB.NET中的页面重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆