0

I'm still using webforms. At the moment I'm not planning to use MVS, despite this I need / I would like to use Ajax with jQuery but to do this I need to create a static [WebMethod] that acts as static, no session nor common things can be used, such getting things from DB using user data stored in session, at least easy way session[]=.

[WebMethod]
    public static void setAsRead(string rowid){}

(In the previous code I need to store in the page, as hidden field, the rowid of the table row which I need its data)

So I wonder whether placing a lot of pagemethods to do so is "normal" or we have to avoid this approach. I personally think that it's ugly to see this because the page nature, it's a webform, a page, not a webservice stack.

So what do you think? Are there security issues? Do I have to avoid ajax with webforms and thinking to migrate to MVC?

Eonasdan
  • 7,563
  • 8
  • 55
  • 82
anmarti
  • 5,045
  • 10
  • 55
  • 96

2 Answers2

1

There's nothing wrong with PageMethods in classic WebForms in terms of security or performance. They are much better than the UpdatePanels as you have full control over the data that is being exchanged between the client and the server. The benefit of using PageMethods compared to raw IHttpHandler is that the framework will take care of the JSON serialization and the plumbing code for you.

So you could PageMethods until you decide to upgrade to ASP.NET MVC, ASP.NET Web API or ServiceStack where you could expose a REST API.

Do I have to avoid ajax with webforms and thinking to migrate to MVC?

No, there's absolutely nothing wrong with doing AJAX in WebForms. People have been using it much before ASP.NET MVC ever existed. But if you are starting a new project you might really consider whether it wouldn't be worth the effort to migrate to ASP.NET MVC. This will very much depend on the specific requirements of your project, the existing codebase, ... Make sure you evaluate all possibilities really well before starting the migration process.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

You don't need to move Asp.net MVC fo implementing ajax. You do still have options in Web Forms. Most of technologies are not Mvc spesific. You can use lots of technologies for backend.

  • Http Handler : This is most basic one and most of the time my personel choice. You can use session by implementing IRequiresSessionState How to POST data to ASP.NET HttpHandler?

  • Asp.net web-api This is the new shiny thing. Lots of godies. Support selfhosting etc.

  • Service stack If you are allowed to use 3rd party libraries. This one is definetly worth looking. Well documented, supported open source project.

Community
  • 1
  • 1
adt
  • 4,320
  • 5
  • 35
  • 54