ASP. Net forms POST to other pages to share

  • 2020-12-05 17:09:28
  • OfStack

In ASP, we typically submit the form to another page (the accept data page). But in ASP.NET, server-side forms are usually submitted to this page if I set them


form1.action="test.aspx";

This will result in a view validation error error because of the ES7en.net security mechanism. We can also turn this validation off by adding the header to the accept page (test.aspx)

 <%@ Page EnableViewStateMac="false" %>

asp.net 2.0 also provides a way to submit to other pages, and the server button control provides one property: PostBackUrl, which is written like this

button1.PostBackUrl="test.aspx";

This does not cause validation errors and is safe.

--------------------------------------------------------------------------------------

By the way, there are 1 ways to dynamically change form form properties. 1 There are some methods that have nothing to do with the above: for example, changing target properties

General page:


((System.Web.UI.HtmlControls.HtmlForm)this.FindControl("form1")).Target = "_blank";

or

form1.Attributes["target"] = "_blank";

Master page master:

((System.Web.UI.HtmlControls.HtmlForm)this.Master.FindControl("form1")).Target = "_blank";

Front desk modification:

<asp:Button ID="btnSubmit" runat="server" Text="Button" onclick="btnSubmit_Click"OnClientClick="this.form.target='_blank'" />


Related articles: