Custom parameter for WebMethod

4 posts, 0 answers
  1. Sandeep
    Sandeep avatar
    3 posts
    Member since:
    Oct 2008

    Posted 06 Feb 2013 Link to this post

    Hi,

    I am using RadAutoCompleteBox (Q3 2012 SP2) & Binding it with WebMethod like:
    <telerik:RadAutoCompleteBox ID="rdtxt" runat="server" Width="90%" EmptyMessage="enter country to search" InputType="Token" Filter="StartsWith" AllowCustomEntry="true">
    <TextSettings SelectionMode="Single" />
    <WebServiceSettings Method="GetCountries" Path="frmPage1.aspx" />
    </telerik:RadAutoCompleteBox>
    It works fine. Fetching countries from server method GetCountries().

    Now, I want to fetch State for that selected/entered country.
    How to pass that country to WebMethod of GetState(object countryData) ?

    Plz reply asap.
  2. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 11 Feb 2013 Link to this post

    Hello Sandeep,

    As far as I understand - you want to pass a parameter to the WebService Method that you use to populate the RadAutoCompleteBox with data.
    You can make this by handling the OnClientRequesting event handler and attach the parameter to the RadAutoCompleteContext in this way:


    <script type="text/javascript">
     
              function OnClientRequesting(sender, eventArgs) { debugger;
                   var context = eventArgs.get_context();
                      context["Country"] = "UK";
                  }
     
          </script>
          <telerik:RadAutoCompleteBox runat="server" ID="RadAutoCompleteBox1"
              OnClientRequesting="OnClientRequesting">
              <WebServiceSettings Path="LoadEntries.asmx" Method="GetNames" />
          </telerik:RadAutoCompleteBox>

    [WebMethod]
    public AutoCompleteBoxData GetNames(RadAutoCompleteContext context)
    {
        string name = context["Country"].ToString();
        ...
        ...
        ...
        }

    Regards,
    Kalina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sandeep
    Sandeep avatar
    3 posts
    Member since:
    Oct 2008

    Posted 04 Mar 2013 Link to this post

    Thanks Kalina,

    One more thing, Can I use PageHandlers (.ashx) instead of WebMethod to bind AutoComplete control ?

    Like: GenericPageHandler.ashx?src=autoCmplt

    & return json object from code.
  5. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 07 Mar 2013 Link to this post

    Hello Sandeep,

    Using a Generic Handlers to bind the RadAutoCompleteBox is not a supported scenario. Therefor, I can suggest you to use the WebMethod, as you intended to do.

    Greetings,
    Nencho
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top