Question

We've had a requirement from a client to move a site that is running on it's own domain to a subfolder of another app.

I've acheived this using ISAPI rewrite proxying.

However, there is one form that does a post back in the site. The generated url for the action from ASP.NET is "/sign-up.aspx?". This sends the postback to the root of the site.

I want to change this to "sign-up.aspx?" (no leading slash). This would be fine if I wasn't using Master pages as I could get a reference to the form and change it's action (this is .NET 3.5 SP1). I've tried to use the following code in my control to get a reference to the form but it doesn't seem to do anything. It finds the form but the action is not set to the value.

        HtmlForm form = ControlLocator.FindControl<HtmlForm>(Page.Master.Master, "form1");
        form.Action = "sign-up.aspx?";

This is in Page_Load and ControlLocator.FindControl is a port of this http://www.west-wind.com/Weblog/posts/5127.aspx

Any ideas?

Cheers, Rob

Was it helpful?

Solution 4

Eventually figured out that it was umbraco's Form.browser that was rewriting the post back url after I had changed it. (Apologies for not mentioning the use of umbraco in my original question).

OTHER TIPS

Good to solve your problem. But for whom that wants to change the action URL of aspnetform, use this simple code in the Page_Load event (even they have a master page).

protected void Page_Load(object sender, EventArgs e)
{
    this.Form.Action = "URL Goes Here";
}

have you tried doing it in page_prerender?

It could be that all the master content merging has not yet been done in page_load. Assuming HtmlForm is the correct type and that the form is actually called 'form1' - which I'm sure is correct.

If you have a button on the signup form you could use the postBackUrl attribute of it to redirect the postback to a different URL.

<asp:button id="SignUpBtn" 
            runat="server"
            postbackurl="sign-up.aspx" 
            value="Sign Up" />

You can find more information on this under "Cross-page Posting in ASP.NET Web Pages".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top