Passing an instance to a generic method in VB.NET

I was deeply immersed in an existing VB.NET project at work. I have never used VB.NET, so I'm struggling a bit. Does anyone know how to solve the following.

I need to pass the instance to the client side and then pass it to the shared method in order to access the instance methods when using the generic method.

The starting point is the HTML file upload control of my Contacts.aspx file:

<asp:FileUpload ID="DocUpload1" runat="server" onchange="CallMe();" />

The onchange event calls the javascript method, see below, it uses AJAX PageMethods to call the Shared method in my code for

This is the script code that is in my Contact.aspx file

    <script language="javascript">
      function CallMe() {
          // call server side method
          PageMethods.GetContact(0, CallSuccess, CallFailed, null);
      }

      // set the destination textbox value with the ContactName
      function CallSuccess(res, destCtrl) {
      }

      // alert message on some failure
      function CallFailed(res, destCtrl) {
          alert(res.get_message());
      }        

</script>

, , , " As Contacts" WebMethod, , :

Contacts.aspx.vb.

Partial Class Contacts

    <System.Web.Services.WebMethod()> _
    Public Shared Function GetContact(ByVal instance As Contacts) As String
        Return instance.GetContactName()  'This is an instance class which I need to call.
    End Function

    'This is my instance class which I want to call from the Shared Class.
    Public Shared Function GetContactName() As String
        Return "Fred Bloggs"
    End Function

End Class

- , , , , , , . , .

+3
1

, ( instance), ASP.Net, PageMethod - , ..

, PageMethods (, , -). , - , , PageMethod, instance.

, :

session("ContactID") = instance

PageMethod :

Public Shared Function GetContact(ByVal key As String) As String
    Return HttpContext.Current.Session(key).GetContactName()  
End Function

key - , .

javascript:

 function CallMe() {
          // call server side method
          PageMethods.GetContact('ContactID', CallSuccess, CallFailed, null);
 }
+2

Source: https://habr.com/ru/post/1772999/


All Articles