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
.NET ProgrammingASP.NETVisual Basic.NETC#

Avatar of undefined
Last Comment
SimonPrice3376
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
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.
Avatar of SimonPrice3376

ASKER

I had to adapt this slightly but got what I needed from this thank you very much.
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo