简体   繁体   中英

Change form action in WebForms ASP.NET C#

How do you change the form action in WebForms to post to a different page, not to a page in your application. Is it possible to use 'response.redirect' to post to a third party page?

Since the form tag exist in the master page, it will always postback to itself. Normally, I would use response.redirect to post to another page within my application, but I don't know about to a third party page. I've tried to give the form an ID and then change it on the page when it loads,

form1.Action = "myURL";

But it doesn't recognized the ID because it only exist in the master page.

If you want to change the form action of the masterpage to post to a third party page you need to find the control on the content page and then update the property as above. Use this in your page load for the content page:

protected void Page_Load(object sender, EventArgs e)
{
    var form =   (HtmlForm)this.Master.FindControl("form1");
    form.Action = "http://blarg.com";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM