I am trying to use PageMethods to call a function from the server side, but I am getting an error that PageMethods is undefined.
Here is what I have put into the html
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePageMethods="True">
and here is the function from the code behind.
<System.Web.Services.WebMethod()> _
Public Function LoadChild(ByVal EntityID, ByVal EntityCat, ByVal lnType, ByVal FullExpand, ByVal lnEquip, ByVal lnTemplate) As String
and here is the call to the function using page methods.
PageMethods.LoadChild(lnEntityID, lnEntityCat, GLOBALEQUIPID, FullExpand, 0);
can anyone see why I would keep getting a PageMethods undefined error? Thank you.
edit - part of the issue may be because the function isnt shared, but when shared is put in, i get this error in about 15 places. - this is refering to the session I am using - here is a snippet of the session being used that is showing an error.
prm4.Value = Session.Item("user_id")
I am getting the word session underlined with the error message below - any suggestions on how to fix this? this could fix the whole issue all together.
Error 305 Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.
I am trying to use PageMethods to call a function from the server side, but I am getting an error that PageMethods is undefined.
Here is what I have put into the html
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePageMethods="True">
and here is the function from the code behind.
<System.Web.Services.WebMethod()> _
Public Function LoadChild(ByVal EntityID, ByVal EntityCat, ByVal lnType, ByVal FullExpand, ByVal lnEquip, ByVal lnTemplate) As String
and here is the call to the function using page methods.
PageMethods.LoadChild(lnEntityID, lnEntityCat, GLOBALEQUIPID, FullExpand, 0);
can anyone see why I would keep getting a PageMethods undefined error? Thank you.
edit - part of the issue may be because the function isnt shared, but when shared is put in, i get this error in about 15 places. - this is refering to the session I am using - here is a snippet of the session being used that is showing an error.
prm4.Value = Session.Item("user_id")
I am getting the word session underlined with the error message below - any suggestions on how to fix this? this could fix the whole issue all together.
Error 305 Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.
Share Improve this question edited Apr 25, 2012 at 17:57 njj56 asked Apr 25, 2012 at 17:17 njj56njj56 6214 gold badges20 silver badges51 bronze badges 4- Have you verified that the ASP.NET Ajax scripts are being included on the page? Also, that your call occurs after their inclusion? – Tejs Commented Apr 25, 2012 at 17:22
- how can i check to make sure these are included? sorry, this is my first time using page methods, and I've taken the instructions from here codeproject./Articles/180355/… – njj56 Commented Apr 25, 2012 at 17:27
- Use Fiddler and a page inspection tool like FireBug for Firefox, F12 dev tools for IE, Inspect Page for Chrome, etc... – Tejs Commented Apr 25, 2012 at 17:27
- is there anyway to just check for this with visual studio? it may be something simple I am missing like an import or reference – njj56 Commented Apr 25, 2012 at 17:30
1 Answer
Reset to default 6Page method should be a static(C#)/shared(VB.NET) method. Otherwise it does not work.
Yes, you can not refer instance property in static method. To get Session
object you could use HttpContext.Current.Session
.