locked
Cascading Dropdown; Getting value of ContextKey RRS feed

  • Question

  • User302996713 posted

    I need help on how to get value in the context key.

    Below is my html code

    <ajaxToolkit:CascadingDropDown ID="ccd4" runat="server"
          ServicePath="~/Vehicles.asmx" ServiceMethod="GetEngines"
          TargetControlID="DropDown4" LoadingText="Loading..."  ParentControlID="DropDown3" Category="Engine" 
          PromptText="Select Engine" UseContextKey="true"  ContextKey='<%# Bind("DropDownn1") + "," + Bind("DropDown2")+ "," + Bind("DropDown3")  %>' />
    

     In my web method I need the split the context key string to get single value of dropdown 1, dropdown 2 and 3 but I dont know how  to get the context key string.

    Saturday, November 15, 2014 4:21 AM

Answers

  • User-1360095595 posted

    It's part of the webmethod signature. It's the third parameter of the method: contextKey.

    Look at the method signature here: http://www.ajaxcontroltoolkit.com/AutoComplete/AutoComplete.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 15, 2014 7:26 AM
  • User61956409 posted

    Hi Bbaale,

    Thanks for your post.

    In my web method I need the split the context key string to get single value of dropdown 1, dropdown 2 and 3 but I dont know how  to get the context key string.

    We could use the context key to send through additional values, as MetalAsp.Net said, if the context key is used, you should add the same signature with an additional parameter named contextKey of type string in your webmethod, then you could get the context key via this parameter.

    You could refer to this blog to get the context key.

    Hope it will be helpful to you.

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 17, 2014 10:25 PM
  • User302996713 posted

    Thank you for the reply I was able to do it. I hope this helps someone some day

    I added the context key using javascript like below

    <script>
            function AddKeys() {
                $find("bccd").set_contextKey("value1" + ":" + dropdown1.value + ";" + "value2" + ":" + dropdown2.value + ";" + "value3" + ":" + dropdown3.value + ";");
            }
     </script>

    then I used on change event to call the function.

    <asp:DropDownList ID="dropdown4" ClientIDMode="Static" onchange="javascript:AddKeys();" runat="server"></asp:DropDownList>

    I set the clientIDMode to static its because when using master pages new ids are assigned to the controls which makes things not to work.

    And I set the ajax control like so 

    <ajaxToolkit:CascadingDropDown ID="ccd4" runat="server" ServicePath="~/Vehicles.asmx" ClientIDMode="Static" ServiceMethod="GetEngines" BehaviorID="bccd4" TargetControlID="dropdown5" LoadingText="Loading..."  ParentControlID="dropdown4" Category="Engine" PromptText="Select Engine" UseContextKey="true"/>

    Finally in my webmethod

    [WebMethod]
        public CascadingDropDownNameValue[] GetEngines(string knownCategoryValues, string category, string contextKey)
        {
            
            StringDictionary ck = CascadingDropDown.ParseKnownCategoryValuesString(contextKey);
    
            //Get First Value
            string v1 = "";
            if (!ck.ContainsKey("value1") || ck["value1"] == null)
            {
                return null;
            }
            else
            {
                v1 = ck["value1"];
            }
    
            //Get Second Value
            string v2 = "";
            if (!ck.ContainsKey("value2") || ck["value2"] == null)
            {
                return null;
            }
            else
            {
                v2 = ck["value2"];
            }
    
           .......


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 18, 2014 4:54 PM

All replies

  • User-1360095595 posted

    It's part of the webmethod signature. It's the third parameter of the method: contextKey.

    Look at the method signature here: http://www.ajaxcontroltoolkit.com/AutoComplete/AutoComplete.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 15, 2014 7:26 AM
  • User61956409 posted

    Hi Bbaale,

    Thanks for your post.

    In my web method I need the split the context key string to get single value of dropdown 1, dropdown 2 and 3 but I dont know how  to get the context key string.

    We could use the context key to send through additional values, as MetalAsp.Net said, if the context key is used, you should add the same signature with an additional parameter named contextKey of type string in your webmethod, then you could get the context key via this parameter.

    You could refer to this blog to get the context key.

    Hope it will be helpful to you.

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 17, 2014 10:25 PM
  • User302996713 posted

    Thank you for the reply I was able to do it. I hope this helps someone some day

    I added the context key using javascript like below

    <script>
            function AddKeys() {
                $find("bccd").set_contextKey("value1" + ":" + dropdown1.value + ";" + "value2" + ":" + dropdown2.value + ";" + "value3" + ":" + dropdown3.value + ";");
            }
     </script>

    then I used on change event to call the function.

    <asp:DropDownList ID="dropdown4" ClientIDMode="Static" onchange="javascript:AddKeys();" runat="server"></asp:DropDownList>

    I set the clientIDMode to static its because when using master pages new ids are assigned to the controls which makes things not to work.

    And I set the ajax control like so 

    <ajaxToolkit:CascadingDropDown ID="ccd4" runat="server" ServicePath="~/Vehicles.asmx" ClientIDMode="Static" ServiceMethod="GetEngines" BehaviorID="bccd4" TargetControlID="dropdown5" LoadingText="Loading..."  ParentControlID="dropdown4" Category="Engine" PromptText="Select Engine" UseContextKey="true"/>

    Finally in my webmethod

    [WebMethod]
        public CascadingDropDownNameValue[] GetEngines(string knownCategoryValues, string category, string contextKey)
        {
            
            StringDictionary ck = CascadingDropDown.ParseKnownCategoryValuesString(contextKey);
    
            //Get First Value
            string v1 = "";
            if (!ck.ContainsKey("value1") || ck["value1"] == null)
            {
                return null;
            }
            else
            {
                v1 = ck["value1"];
            }
    
            //Get Second Value
            string v2 = "";
            if (!ck.ContainsKey("value2") || ck["value2"] == null)
            {
                return null;
            }
            else
            {
                v2 = ck["value2"];
            }
    
           .......


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 18, 2014 4:54 PM