跨页投递。它是一个很好的初步实践来使用Asp.net previousPage? [英] Cross-page posting. Is it a good pratice to use PreviousPage in Asp.net?

查看:173
本文介绍了跨页投递。它是一个很好的初步实践来使用Asp.net previousPage?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这篇文章在MSDN上谈论跨页投递

I found this article on MSDN talking about Cross-page posting.

我从未与页。previousPage工作。但我认为它有趣。

I never worked with Page.PreviousPage. But I think its interesting.

你用了吗?它是一个很好的初步实践,还是一个坏主意?

Do you use it? Is it a good pratice, or a bad idea?

你觉得呢?

感谢。

推荐答案

交叉页投递是一个帮手一些数据发布到不同的页面,仍然有ASP .NET code后面的功能。

The cross page posting is a helper to post some data to a different page and still have the asp.net code behind functionality.

这是为什么存在?由于asp.net有局限性一,并且每页唯一形式。但实际上到HTML页面,您可以有许多形式和很多不同的岗位不同的页面。

Why is this exist ? because asp.net have a limitation of one and only form per page. But actually to an html page you can have many forms and many different post to different pages.

于是给一个工具,这样的话,更是让你设置第二个页面发布的数据,在安装此的按钮(而不是把第二种形式),并从那里为解决这个问题,张贴数据到不同的页面。

So to give a tool to that case, is let you set a second page to post the data, and you setup this on the Button (and not by placing second form), and from there is solve this issue, to post the data to a different page.

例如...与出asp.net和一个页面上简单的HTML就可以做到这一点。

For example... with out asp.net and with simple html on a page you can do that.

<body>
<form method="post" action="samepage.html">
   Username: <input type="text" name="user" />
   <input type="submit" value="Submit" />
</form>

<form method="post" action="page_b.html">
   email for news letter: <input type="text" name="email" />
   <input type="submit" value="Submit" />
</form>
</body>

要解决这样的情况,因为asp.net不允许在同一页面两种形式,给出了这样的选择。

To solve a situation like this, and because asp.net not allow two forms at the same page, gives this option.

<body>
<form id="form1" runat="server">
Username: <asp:TextBox runat="server" ID="Name" />
<asp:Button runat="server"/>

email for news letter: <asp:TextBox runat="server" ID="email" />
<asp:Button runat="server" PostBackUrl="page_b.aspx" />

</form>
</body>

在第二种情况下,你有一种形式,但您设置的一项PostBackUrl到不同的页面,并从那里asp.net还是处理第二页(与出重定向)上直接背后code中的数据。

In the second case, you have one form, but you set the PostBackUrl to a different page, and from there asp.net still handle the data on code behind direct on a second page (with out redirect).

我希望这个例子给你和一个知道在哪里,真正使用previous页面。另外更重要的是通常是重定向,怎么过有您需要有结果,到不同的页面情况。因此,它的每情况下,如果你使用与否。

I hope this example gives you and an idea where to really use the previous page. Also what is more usually is the Redirect, how ever there are case that you need to have the result to a different page. So its per case if you use it or not.

这篇关于跨页投递。它是一个很好的初步实践来使用Asp.net previousPage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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