Link to home
Start Free TrialLog in
Avatar of SimonPrice3376
SimonPrice3376

asked on

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

Hi

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

        Try
            PrepareAndPassData(id)

            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()
        listOfParameters.Add(validatedPaymentsParam)

        'Dim dt = DataAccessLayer.GetDataAsDatatable(listOfParameters, _connstr, "usp_GetValidatedRecordsForPayment")
        'WriteToExcel(dt)
        Try
            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.

Thanks

Simon
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SimonPrice3376
SimonPrice3376

ASKER

Thanks for the quick response, I will try this out tomorrow when I am back in the office.
I had to adapt this slightly but got what I needed from this thank you very much.