locked
call subroutine from function RRS feed

  • Question

  • User2025297061 posted

    Maybe a dumb question but... here we go...

    I am calling a server side Function from a client side function. I got the example from the Internet. It works fine but I need more functionality.  Here is the Server side Function that is called.

    <System.Web.Services.WebMethod()> _
    Public Shared Function MyFirstParameterPageMethod(ByVal strVal As String) As String
    HttpContext.Current.Session("svThemeID") = strVal
    'BindGrid()
    Return "Welcome to the world of AJAX.NET , the value you passed is : " + strVal
    End Function

     This client sends in the ID I need and the Welcome to... puts it on the screen. But, I aslo need to rebind a grid that is on the display. When I try this I get this.....

    Error 2 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. 

    The BindObjectiveGrid does exist and can be called. I just don't know what this error means or how to fix it.   Can you help me?  Thanks

    Monday, June 23, 2008 8:20 PM

All replies

  • User-1175124238 posted

    Webmethods are static thus you cannot call a member method or variable of the class where you implemented your webmethod.

    Tuesday, June 24, 2008 3:43 AM
  • User2025297061 posted

    do you know how I can handle this?  I need to set a session variable to the ID that is sent from client side?  Is there a way to implement this?

    Tuesday, June 24, 2008 11:02 AM
  • User-1175124238 posted

    You can access the Session object as you did on your code. But accessing a member method or variable isn't possible with WebMethods. What I usually do is use callback event manager coz the methods RaiseCallbackEvent, and GetCallbackResult are member methods thus can access other member methods and variables.

    Tuesday, June 24, 2008 11:35 AM
  • User-2045815028 posted

    Kimoy:

    I am having the same problem. I am calling a WebService and need to pass the value selected of a control on the page:

    <script runat="server">

    <System.Web.Services.WebMethod()> _

    <System.Web.Script.Services.ScriptMethod()> _

    Public Shared Function GetCities(ByVal prefixText As String, ByVal count As Integer) As String()

    Return New WLP.AutoComplete().GetCities(prefixText, count, lstCountry.SelectedValue)

    End Function

    </script>

    Do you know how I can retrieve the value indicated in green?

    Thanks,

    Wim.

    Friday, September 5, 2008 8:31 AM
  • User-990694832 posted

    Use

     <System.Web.Services.WebMethod(EnableSession:=True)> _
    To write to the session in the web method.

    Then

    Session("svThemeID") = strVal   ... should work 

     

    a person can't call a method from the calling object in a webservice. 

    Hope this helps

    DK

     

    Friday, September 5, 2008 8:53 AM
  • User-2045815028 posted

    If it cannot be called, how can I change the expected syntax for the WebService knowing it is tied to an AutoCompleteExtender:

    <asp:TextBox ID="txtCity" runat="server"></asp:TextBox>

    <cc1:AutoCompleteExtender ID="extCity" runat="server" TargetControlID="txtCity" ServiceMethod="GetCities" MinimumPrefixLength="3">

    </cc1:AutoCompleteExtender>

    It would great to tell the AutoCompleteExtender to use another ASP Control to pass on on extra variable for the selection criteria.

    Thanks, 

    Wim.
    Belgium.

    Friday, September 5, 2008 9:05 AM