Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form POST in ASP.NET

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?

like image 722
Steven Avatar asked Aug 23 '26 04:08

Steven


2 Answers

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.

like image 175
Marc Gravell Avatar answered Aug 25 '26 18:08

Marc Gravell


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.

like image 30
MStodd Avatar answered Aug 25 '26 20:08

MStodd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!