how to pass additional parameter to CascadingDropDown?

WebSpider 76 Reputation points
2021-07-09T09:03:10.02+00:00

below is my code, how can i pass Label1.text to CascadingDropDown?

<asp:DropDownList ID="ddl_category_parent" runat="server"></asp:DropDownList>                                                               
<cc1:CascadingDropDown ID="cdd_category_parent" runat="server" Enabled="false" category="ParentCat" loadingtext="loading..." 
 promptvalue="Select a parent category" servicemethod="GetParentCategory"
 servicepath="/webservices/category.asmx" targetcontrolid="ddl_category_parent">
</cc1:CascadingDropDown>


    <WebMethod()> _
    Public Function GetParentCategory(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()

        Dim values As New List(Of CascadingDropDownNameValue)()
        Dim parent_cat_name As String

        Dim keyword as String = xxxxxx (Label1.text)

        DT = DBcategory.return_category_detail("Status", "Admin", keyword, "Product", "parent", "", "Active", "")

        For x As Integer = 0 To DT.Rows.Count - 1
            parent_cat_name = DT.Rows(x).Item("name1").ToString
            values.Add(New CascadingDropDownNameValue(HttpUtility.HtmlDecode(parent_cat_name), DT.Rows(x).Item("ID")))
        Next

        Return values.ToArray()

    End Function
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,541 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,086 Reputation points
    2021-07-12T03:28:08.477+00:00

    Hi @WebSpider ,
    As far as I think,you could use the ContextKey to pass the additional parameter.You need to do like this:

    1. Set UseContextKey property on the CascadingDropDown to true
    2. Change the method signature of your webmethod to accept the contextKey parameter:
      • Public Function GetParentCategory(ByVal knownCategoryValues As String, ByVal category As String,ByVal contextKey As String) As CascadingDropDownNameValue()
    3. Set the ContextKey using JavaScript/Jquery. The AJAX CascadingDropDown exposes getter/setter for this property in the DOM:
      • document.getElementById('Label1').set_contextKey('valueyouwant');
      Just like this: <asp:DropDownList ID="ddl_category_parent" runat="server" o nchange="CategoryChanged()"></asp:DropDownList>
      <cc1:CascadingDropDown ID="cdd_category_parent" runat="server" Enabled="false" category="ParentCat" loadingtext="loading..."
      promptvalue="Select a parent category" servicemethod="GetParentCategory"
      servicepath="/webservices/category.asmx" targetcontrolid="ddl_category_parent">
      </cc1:CascadingDropDown>

    Javascript:

    <s cript type="text/javascript">  
        function CategoryChanged() {  
           $find('<%=Label1.ClientID%>').set_contextKey($get("<%=Label1.ClientID %>").value);  
        }  
    </script>  
    

    Code-behind:

     <WebMethod()> _  
                 Public Function GetParentCategory(ByVal knownCategoryValues As String, ByVal contextKey As String) As CascadingDropDownNameValue()  
                ......  
                End Function  
    

    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.