3

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

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

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

What do you think about?

Thanks.

  • 1
    I don't believe it's a good fit for StackOverflow as there's no exact answer - it's a matter of opinion really, but may be suitable for programmers.stackexchange.com. My 2c is that it's not the usual behaviour for postbacks so many other developers may get caught out by this functionality, and it would be better to use, as the article suggests, the Wizard control, as it is specifically designed for that purpose, so the intent is clear. – dash Apr 12 '12 at 13:14
  • @dash well, is not bad idea to write some thinks about that, and why exist. – Aristos Apr 12 '12 at 13:45
  • 1
    @Aristos I agree, but that kind of question belongs more on programmers.stackexchange.com - it's not a bad question, but it's not a great fit for the QA format for StackOverflow - IMO of course, which is why I've upvoted your answer, because it's a *good* answer. – dash Apr 12 '12 at 15:16
  • Hummmm... I think you all are right. Thanks @Aristos for the good answer. – Guilherme de Jesus Santos Apr 12 '12 at 18:35

1 Answers1

4

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

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.

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>

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>

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).

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.

Aristos
  • 66,005
  • 16
  • 114
  • 150