Search code examples
c#asp.netwebformsprogressive-enhancement

Plain old HTTP GET using a <form> tag with ASP.NET


I've got a WebForms site built using Progressive Enhancement which uses Master pages. Obviously, the tag is injected by default by ASP.NET so it can manage the postbacks.

I need a way of doing the following

<form action="new_url" method="get">
 <input ... />
</form>

Obviously, .NET is intercepting the request with the outer and posting back to itself. I can do this with JavaScript but then I'll break the Progressive Enhancement policy of my website. Is this not possible without essentially building an ASP.NET Server Control to manage the redirection?

Thanks Martin


Solution

  • The tag should be well visible in your source file, with a runat="server". However, it shouldn't be possible to add another form tag inside another one and you can't have two <form runat="server">.

    So, one way to achieve this would be to append the form after the existing one. It might not be possible with your current MasterPages / Pages / UserControls setup, especialy if you got the <form runat="server"> tag in the MasterPage.

    So, you can either reevaluate your structure using nested master pages so you can choose which pages will actually use the PostBack feature and use a <form>less MasterPage for the other pages.

    Another way would be to use javascript to build an URL from some fields.

    Have a look at this post, it might help you: Multiple forms on ASP.NET page