We help IT Professionals succeed at work.
Get Started

cannot refer to an instance member of a class from within a shared

Last Modified: 2016-01-14

I am trying to get an AJAX call working from asp.net working with VB. However, I am getting the error as per the above with when I am trying to pass an Id to a new method.

the code I am using is

<System.Web.Services.WebMethod()> _
    Public Shared Function writeSingleRecord(ByVal id As Long) As Boolean


            Return True

        Catch ex As Exception
            Return False

        End Try

    End Function

Public Sub PrepareAndPassData(id As Long)
        Dim listOfParameters As New List(Of SqlParameter)

        Dim validatedPaymentsParam As New SqlParameter("@Id's", SqlDbType.BigInt)
        validatedPaymentsParam.Value = getValidatedPayments()

        'Dim dt = DataAccessLayer.GetDataAsDatatable(listOfParameters, _connstr, "usp_GetValidatedRecordsForPayment")
            WriteToExcel(DataAccessLayer.GetDataAsDatatable(listOfParameters, _charterProdConnstr, "usp_GetValidatedRecordsForPayment"))

        Catch ioEx As System.IO.IOException

            PassToErrorHandler(ioEx, System.Reflection.MethodInfo.GetCurrentMethod().ToString(), System.Reflection.Assembly.GetExecutingAssembly().GetName().Name)

        Catch ex As Exception
            PassToErrorHandler(ex, System.Reflection.MethodInfo.GetCurrentMethod().ToString(), System.Reflection.Assembly.GetExecutingAssembly().GetName().Name)

        End Try
    End Sub

Open in new window

if I make the method a shared method this then causes the same error on my other methods.

In the method of WriteToExcel() if I make this a shared sub then Server.MapPath has this same issue too, along with other methods that are referred to too such as PassToErrorHandler.

And in the GetValidatedPayments method,

using this line

Dim cph As System.Web.UI.WebControls.ContentPlaceHolder = Master.FindControl("MainContent")

Open in new window

causes the same error on Master.

Any and all help very much appreciated.


Watch Question
Distinguished Expert 2019
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE