Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Method Not Valid in Given Context - Did you mean to invoke a method?

Status
Not open for further replies.

LowBrow

Technical User
Jun 1, 2001
100
US
I am getting two errors for a piece a code which seems fairly straight-forward. I am working on a C#/ASP.NET app. I have a control that sits in my Template.Master and once the user logs in, presents a list of clients the user is tracking.

Code behind page for control
The errors are returned referencing this code. Specifically this line:
Code:
(NWC.CSWeb.BLL.Program.TrackedClient.GetTrackedClientCount.Value > 0)
with the error NWC.CSWeb.BLL.Program.TrackedClient.GetTrackedClientCount(string) is a method, which is not valid in the given context.

The second error comes the line:
Code:
repTrackedClient.DataSource = NWC.CSWeb.BLL.Program.TrackedClient.GetTrackedClients
With the error Cannot convert method group to non-delegate type object. Did you intend to invoke a method?
Code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NWC.CSWeb;
using NWC.CSWeb.BLL.Program;
using NWC.CSWeb.UI;

namespace NWC.CSWeb.UI.Controls
{
    public partial class TrackedClientBox : BaseWebPart
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                if (NWC.CSWeb.BLL.Program.TrackedClient.GetTrackedClientCount.Value > 0)
                {
                    repTrackedClient.DataSource = NWC.CSWeb.BLL.Program.TrackedClient.GetTrackedClients;
                    repTrackedClient.DataBind();

                    panLinkTrackedClients.Visible = true;
                    lblNoTrackedClients.Visible = false;
                }
                else
                {
                    panLinkTrackedClients.Visible = false;
                    lblNoTrackedClients.Visible = true;
                }
            }
        }
    }
}

From BLL.Program.TrackedClient.CS
Code:
      /// <summary>
      /// Returns the number of Tracked Clients for the current user
      /// </summary>
       public static int GetTrackedClientCount(string addedBy)
      {
          int trackedClientCount = 0;
          string key = "Program_TrackedClientCount_" + addedBy;

          if (BaseProgram.Settings.EnableCaching && BizObject.Cache[key] != null)
          {
              trackedClientCount = (int)BizObject.Cache[key];
          }
          else
          {
              trackedClientCount = SiteProvider.Program.GetTrackedClientCount(addedBy);
              BaseProgram.CacheData(key, trackedClientCount);
          }
          return trackedClientCount;
      }
From SQLProvider
Code:
      /// <summary>
      /// Returns the number of Tracked Clients for the current user
      /// </summary>
      public override int GetTrackedClientCount(string addedBy)
      {
          using (SqlConnection cn = new SqlConnection(this.ConnectionString))
          {
              SqlCommand cmd = new SqlCommand("nwc_Program_GetTrackedClientCount", cn);
              cmd.CommandType = CommandType.StoredProcedure;
              cmd.Parameters.Add("@AddedBy", SqlDbType.NVarChar).Value = addedBy;
              cn.Open();
              return (int)ExecuteScalar(cmd);
          }
      }

I am not proficient with C#, but this seems straightforward to me. The Stored Procedure returns and integer. If the value is greater than 0, return the list of clients using GetTrackedClients, else, show the label for no tracked clients.
Any help would be appreciated. Even a more definitive description of the two errors, and whether or not they are related to each other, or represent two different errors in the code.
 

TrackedClient is a method

Code:
// replace this
// (NWC.CSWeb.BLL.Program.TrackedClient.GetTrackedClientCount.Value > 0)
// with this:
   (NWC.CSWeb.BLL.Program.TrackedClient[COLOR=red]()[/color].GetTrackedClientCount.Value > 0)



mr s. <;)

 
Thank you very much for the assistance, but this doesn't work. The method is 'GetTrackedClientCount(string addedBy)' for the Public Class 'TrackedClient' (from TrackedClient.CS), within the 'Program' NameSpace. I have tried adding (), (string addedBy), (string), and even (int) to the end of GetTrackedClientCount. Each of these triggered errors.
 
the four examples you give are mostly all declarations. what you need is a call:
Code:
 method() // declares or calls a method with no parameters
 method(string addedBy) // declares a method with one parameter of type string called addedBy
 method(string) // declares a method with one parameter of type string 
 method(int) // declares a method with one parameter of type int

 method(variable); // passes a variable of type string to the method

//so, if you have a variable of type string called aVariable
(NWC.CSWeb.BLL.Program.TrackedClient[COLOR=red](aVariable)[/color].GetTrackedClientCount.Value > 0)


mr s. <;)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top