Home > Article > Backend Development > How to POST form in asp.net to other pages
In ASP, we usually submit the form to another page (accepting data page). But in ASP.NET, server-side forms are usually submitted to this page. If I set
form1.action="test.aspx";
, it will cause a view validation error, because Asp.net caused by safety mechanisms. We can also turn off this verification and add
in the header of the acceptance page (test.aspx) <%@ Page EnableViewStateMac="false" %>
But this is not very safe. In fact, asp.net 2.0 is still Provides a way to submit to other pages. The server button control provides an attribute: PostBackUrl. Write like this
button1.PostBackUrl="test.aspx";
This will not cause verification errors and is very safe. .
------------------------------------------------ ----------------------------------------
By the way, here is a way to dynamically modify form attributes. Some methods have nothing to do with the above: For example, modify the target attribute
Normal page:
((System.Web.UI.HtmlControls.HtmlForm)this.FindControl("form1")).Target = "_blank";
Or
form1.Attributes["target"] = "_blank";
including master page master:
((System.Web.UI.HtmlControls.HtmlForm)this.Master.FindControl("form1")). Target = "_blank";
Front-end modification: