문제

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.

도움이 되었습니까?

해결책

  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

다른 팁

If you try to create a class, VS will ask you if you wont to create a folder for it. All common classes should go in App_code folder. Then you can move your method in that class and reference them from the pages.

How about creating a web service which implements web methods that your user control needs to work properly.

Here is a MSDN article on this topic: http://msdn.microsoft.com/en-us/library/bb515101(v=vs.90).aspx

Hope this helps!

Regards, Uros

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top