Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3933700
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:37:51+00:00 2026-05-19T23:37:51+00:00

I have a code behind page that has several method; one of them is

  • 0

I have a code behind page that has several method; one of them is a page method.

[WebMethod]
public static void ResetDate(DateTime TheNewDate)
{
    LoadCallHistory(TheNewDate.Date);
}

protected void LoadCallHistory(DateTime TheDate)
{ bunch of stuff }

The method LoadCallHistory works fine when the page loads and I can call it from other methods inside the page. However, in the web method part, it gets underlined in red with the error “an object reference is required for the non-static field”.

How do you access functions from the page method part of the code?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T23:37:51+00:00Added an answer on May 19, 2026 at 11:37 pm

    You cannot call a non-static method from a static context without having an instance of the class. Either remove static from ResetDate or make LoadCallHistory static.

    However, if you remove static from ResetDate you must have an instance of it to use that method. Another approach is to create an instance of the class inside ResetDate and use that instance to call LoadCallHistory, something like this:

    [WebMethod]
    public static void ResetDate(DateTime TheNewDate)
    {
        var callHistoryHandler = new Pages_CallHistory();
        callHistoryHandler.LoadCallHistory(TheNewDate.Date);
    }
    

    The error message indicates that ResetDate has the keyword static and LoadCallHistory does not. When using static either both of the methods needs to be static or the called method needs to be static, the caller cannot be static if the called method is not.

    To quote MSDN on “Static Classes and Static Class Members”

    A static class is basically the same
    as a non-static class, but there is
    one difference: a static class cannot
    be instantiated. In other words, you
    cannot use the new keyword to create a
    variable of the class type. Because
    there is no instance variable, you
    access the members of a static class
    by using the class name itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project where a .master page was created without a code behind
I have a import directive in my inline .aspx page (no code-behind). Getting an
I have some code that I am putting in the code-behind of a master
Why is that Web Service files (.asmx) have their code-behind placed in app_code folder
I have a line of C# in my ASP.NET code behind that looks like
I have a simple function that I want to call in the code behind
I always have this notion that writing SQL queries in the code behind is
I have a Page that has a single instance of a UserControl that itself
I have a btnSave_Click() function in my code-behind. If a user clicks the save
I have been able to create ASPX pages without the code behind, but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.