locked
Webservice Webmethod not firing RRS feed

  • Question

  • User-619898029 posted

    Hi All.

    I am using a dropdown list for states and a textbox for cities which have a Autocomplete extender to populate cities based on state selected in the dropdownlist.  from webservice method I am trying to call a function from datalayer. 

    But its not working for me.

    Please find below code

    .aspx

    <asp:DropDownList ID="ddlState" runat="server" AutoPostBack="true"
    OnSelectedIndexChanged ="State_OnSelectedIndexChanged" style="width: 205px;">
    </asp:DropDownList>
    
    asp:TextBox ID="txtCity" runat="server" style="width: 200px;"></asp:TextBox>
    <asp:AutoCompleteExtender ID="aceShipCity" runat="server" TargetControlID="txtCity"
         CompletionInterval="100" CompletionSetCount="10" MinimumPrefixLength="1"
         EnableCaching="true" ServiceMethod="GetCities" UseContextKey="true"
         FirstRowSelected="false">
    </asp:AutoCompleteExtender>

    .aspx.cs

    protected void State_OnSelectedIndexChanged(object sender, EventArgs e)
    {
    try
    {
    aceCity.ContextKey = State.SelectedValue;


    }
    catch (Exception ex)
    {
    }

    }

    public static List<string> GetCities(string strPrefixText, string strStateContextKey)
        {
            List<string> lstCities = new List<string>();
    
            try
            {
                //get cities from the method 
                DataTable dtTempCities = new DataTable();
                CO objCO = new CO();
                dtTempCities = objCO.GetCities(strPrefixText, strStateContextKey);
    
                //store the datatable rows as list<string>
                if (dtTempCities.Rows.Count > 0)
                {
                    for (int i = 0; i < dtTempCities.Rows.Count; i++)
                    {
                        lstCities.Add(dtTempCities.Rows[i]["Cities"].ToString());
                    }
                }
    
                else
                {
                    //no records found
                }
    
            }
    
            catch (Exception ex)
            {
                //do nothing for now
            }
    
            return lstCities;
        }


    Any help would be appreciated

    Wednesday, September 25, 2013 4:32 AM

Answers

  • User-1360095595 posted

    This is a PageMethod, yes? That is, it's not a standalone webservice/webmethod, right?

    Anyway, assuming that is the case, change you signature like this (parameters are case sensitive and must be named as I show below):

    public static List<string> GetCities(string prefixText, int count, string contextKey)

    Hopefully you've enabled pagemethods on the scriptmanager.

    [Edit: added code block.]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 25, 2013 5:05 AM

All replies

  • User289622470 posted

    Hi,

      Have you made your method GetCities a web method using attribute [WebMethod] as shown below

      [WebMethod]

      public static List<string> GetCities(string strPrefixText, string strStateContextKey)
      {

         ........

    Thanks,

    Wednesday, September 25, 2013 4:40 AM
  • User-619898029 posted

    Hi,

      Have you made your method GetCities a web method using attribute [WebMethod] as shown below

      [WebMethod]

      public static List<string> GetCities(string strPrefixText, string strStateContextKey)
      {

         ........

    Thanks,

    Sorry for missing out that two lines

    Below is the code before 

    public static List<string> GetCities(string strPrefixText, string strStateContextKey)
      {....

    }

     [System.Web.Script.Services.ScriptMethod()]
        [System.Web.Services.WebMethod]



    Wednesday, September 25, 2013 4:42 AM
  • User289622470 posted

    Hi,

       Can you see if you are getting a hit in GetCities() method on typing in text box by putting a breakpoint in method GetCities()..?

    Thanks,

    Wednesday, September 25, 2013 4:47 AM
  • User-619898029 posted

    Hi,

       Can you see if you are getting a hit in GetCities() method on typing in text box by putting a breakpoint in method GetCities()..?

    Thanks,

    Yes I have checked...but its not hitting

    Wednesday, September 25, 2013 4:48 AM
  • User289622470 posted

      I believe Ajax control tool kit is porperly configured and you have registered script manager in your page as well. Can you double check

    Thanks,

    Wednesday, September 25, 2013 4:53 AM
  • User-1360095595 posted

    This is a PageMethod, yes? That is, it's not a standalone webservice/webmethod, right?

    Anyway, assuming that is the case, change you signature like this (parameters are case sensitive and must be named as I show below):

    public static List<string> GetCities(string prefixText, int count, string contextKey)

    Hopefully you've enabled pagemethods on the scriptmanager.

    [Edit: added code block.]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 25, 2013 5:05 AM
  • User-619898029 posted

    This is a PageMethod, yes? That is, it's not a standalone webservice/webmethod, right?
    Anyway, assuming that is the case, change you signature like this (parameters are case sensitive and must be named as I show below):
    public static List<string> GetCities(string prefixText, int count, string contextKey)

    Hopefully you've enabled pagemethods on the scriptmanager.

    [Edit: added code block.]

    Worked for me :) !!!

    Thanks for the reply.

    Wednesday, September 25, 2013 5:39 AM