views:

77

answers:

3

I'm trying to convert a classic ASP page to ASP.NET 3.5. The page has several forms on it for several different things.

In ASP.NET, there's a server form control wrapping the entire page, and form controls don't work within a server form control, and you can't have more than one server form control on a page.

So in order to keep this functionality, I can either:

  • Remove the server form control that's wrapping the page, and leaving the html forms on the page.
  • Create button click events for every form and perform the POST in the code-behind.

What's the preferred method here?

+7  A: 

I wonder if converting to vanilla asp.net (aka webforms) is a bad idea here. Personally I'd go to MVC instead - allows multiple forms etc, and the views are much closer to he HTML, a lot like ASP.

I guess I'm saying there are some glitches vanilla asp.net introduces that you don't have to suffer.

Marc Gravell
I agree with this. If you have a choice, choose MVC. It is easy to learn, and I imagine you will be up and running quicker than you would trying to hack everything to work with Web Forms. Plus you'll benefit from having a much cleaner and maintainable design. Hope this helps.
adamisnt
I agree in this case, even though I personally prefer WebForms.
David Stratton
+2  A: 

I would go with the second option, any button click is going to post the whole page back anyway so you're not saving any bandwidth. Simply handle each button appropriately.

MStodd
A: 

Check the answer I provided to a similar question here :-)

http://stackoverflow.com/questions/3320966/how-to-get-past-embedding-a-html-form-for-paypal-buttons-asp-net/3431566#3431566

If you're going to use different button clicks, you still need to use this override to disable the non-related buttons in each handler, otherwise it won't work. You can only have one form tag at a time - this way you can toggle/disable the ones you're not using as appropriate.

Better still, refactor your application to use a single form. While MVC would be a closer match to the model you're using right now, it wouldn't make sense to go that route unless you were experienced enough with it; Web Forms is an easier jump.

IrishChieftain