Search code examples
c#javascriptasp.netwebmethod

Access Web Methods from multiple aspx pages


I have a user control which is used in multiple(4 to be exact) aspx pages. This usercontrol have a couple of Get/Save webmethods. Right now, I placed all the webmethods in one aspx page and kept calling the same ones from my javascript. I would like to place them in a central location that all the aspx pages can see, but not sure how/where. Any suggestions please?

Edit: I know the WebMethods should be a part of a class inherited from 'System.Web.UI.Page'. Is there a better place that I can move these methods to, where js can call from.


Solution

    1. try to creating Generic Handler (.ahx) and put all your code there.
    2. or try to creating base page, where the base page inherited with the all the aspx pages

    in your aspx page :

    public partial class RekapDocumentView : based.PageBase
    {
    
    }
    

    in your new class :

    public class PageBase : System.Web.UI.Page
    {
       //your webmethods
    }
    

    perhaps this can help