0

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.

1
  • I think I figured out the problem. I don't need to apply masterpage to the page that I'm currently on and just code it from scratch, that way I can modify the action in the form. Commented Nov 16, 2016 at 19:30

1 Answer 1

1

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";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.