views:

145

answers:

3

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

+1  A: 

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.

Andras Zoltan
I did try doing it in prerender before page_load, no joy. There is no null reference so the form is definitely being found. Thanks for the answer anyway! :) Maybe I need to do it later in the lifecycle?
Rob Stevenson-Leggett
Just checking - pre-render should happen way after Page_Load- it's one of the last stages before the page is dumped. Did you mean Pre_Init?Could even try it in the start of Render; although it's possible that Asp.Net is simply ignoring any value you give it. What's the value of Form.Action before you try and set it?
Andras Zoltan
+1  A: 

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".

Zhaph - Ben Duguid
A: 

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).

Rob Stevenson-Leggett