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 8992197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:53:55+00:00 2026-06-15T22:53:55+00:00

i have a WebMethod that serves an Ajax AutoComplete Extender as it’s DataSource. FontnmsList_AutCpltDataSrc()

  • 0

i have a WebMethod that serves an Ajax AutoComplete Extender as it’s DataSource.

FontnmsList_AutCpltDataSrc()

so it must be static ,… unless I will implement it through another approach… such as Web Service, as i wouldn’t like to use, and actually, that’s not the issue here anyways.

so … being a static method, and a it needs to co-work with rest of data of current application …that is not static….there’s a little problem here ..

now as i have been advised to refrain from using static in general (was referring asp.net), and while trying to follow that advice,

i could see that in order to allow interaction with it… the web method is kind of leading me to convert all of my other application elements / data types and methods to use a static modifier, for instance ,

this is an example I came across with current project.

// non static 
public SeSn.CurrentSesionVariablsTmplt ExtractSesnVar()
{
    SeSn.CurrentSesionVariablsTmplt RetrndAppGlobals = SeSn.GetValueAS.ACloneOfGlobalsObj("_CurrentSesionGlobals");
    return (SeSn.CurrentSesionVariablsTmplt)RetrndAppGlobals ;

}

now this is the web method that is responsible for autocomplete extender

public static List<string> FntsList = new List<string>();


[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod(EnableSession = true)]

public static List<string> FontnmsList_AutCpltDataSrc(string prefixText)
{ 

    if (ExtrctSesnVar().Fntlist != null)
    { 
        //here too , non of these are , except for the List of course
        FntsList = RflectMeths.ClassFldsAsList<fntNams>();
        CurrSesnDatabag.Fntlist = FntsList;
        SeSn.Modify(Act.Add, App.VarNms._CurrentSesionGlobals, CurrSesnDatabag);
    }
    else
        FntsList = ExtractSesnVar().Fntlist;

    return AutoComplete.FromListStr(prefixText, FntsList);
}

so a non-static ExtractSesnVar() is required for work within

a static web method FontnmsList_AutCpltDataSrc() scope.

so it makes me wonder …
What basic knowledge am I lacking here (:
I mean, did you ever get in to this junction when you started learning .net ?

and as for what is called in SO A Real Question :

what is the work around as a solution to this scenario,(its only one example . as there should be many other ‘junctions’ like this one, that you could come up with)

I should think there’s supposed to be some way, to bridge between these two entities while writing I could think of passing in data which is non static as parameter ,

so what am i missing here . what is the correct solution as for the subjetced code above ?

  • 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-06-15T22:53:56+00:00Added an answer on June 15, 2026 at 10:53 pm

    I’m assuming you’re asking: How can I call instance methods from a static method?

    There are only 3 options:

    1. You could create a single static instance of the object that has the methods required. This will only work if this instance can be reset or doesn’t hold any state.
    2. You create a new instance on every single call and use it.
    3. Make everything static. (not recommended)

    Sometimes, instance methods only require 1 or perhaps 2 pieces of state information from the instance and in those cases it’s easier to turn them into static and have the instance method call the static method with the extra bit of state information. Check if this is the case here.

    for example, imagine you have a very simple class like this:

    public class something
    {
      public int One { get;set; }
      public int Two { get;set; }
    
      public int Add()
      {
        return One + Two;
      }
    }
    

    and you had a static method that needed to call Add, you could refactor the above code into below code so that you didn’t have to create an instance anymore in your static method, but still had the Add logic in one place:

    public class something
    {
      public int One { get;set; }
      public int Two { get;set; }
    
      public int Add()
      {
        return Add(One, Two);
      }
    
      internal static int Add(int one, int two) 
      {
        return one + two;
      }
    }
    

    I’ve chosen to make the static Add method internal so only other classes in your assembly and friend assemblies can call it. Feel free to make it public if it makes sense in your scenario.

    None of this is ideal, but it might be worthwhile in your case. YMMV.

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

Sidebar

Related Questions

I have a webmethod that returns a Hashtable through a jQuery ajax call along
Is it possible in jax-ws to have a webmethod that creates a new object
In C# I have methods that use [WebMethod(EnableSession = true)] I consume them in
I have a JSON response that is formatted from my C# WebMethod using the
i have an ASP.NET web service that returning a custom entity object (Staff): [WebMethod]
I have a page with this method in CreateTicket.aspx.cs: [WebMethod()] public static string Categories()
I have a web service that has one method: [WebMethod] public bool SyncUserData(string userxml)
I have a jquery Ajax call function that I use to submit form to
I have web methods that are called via AJAX in a .Net 4.0 web
I've got a WebMethod that I'm calling from jQuery AJAX. No matter what 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.