AJAX C# AutoCompleteExtender contextKey

2019-01-29 00:27发布

问题:

How do you dynamically pass parameter/control to contextKey?

<asp:TextBox ID="tbA" runat="server" autocomplete="off"></asp:TextBox> 
<asp:TextBox ID="tbB" runat="server">hello</asp:TextBox> 
<asp:TextBox ID="tbC" runat="server">world</asp:TextBox>

<cc1:AutoCompleteExtender ID="aceListA" ServiceMethod="myListServiceA" ServicePath="WebService.asmx" TargetControlID="tbA" runat="server" EnableCaching="true" UseContextKey="true"> </cc1:AutoCompleteExtender>

  [WebMethod]
   public string[] myListServiceA(string prefixText, int count, string contextKey)

Because I want to check tbB, tbC at Web Service level. I've read this article like 5 times, but still doesn't make a sense out of it, per half missing complete codes.

回答1:

You can set the context key in two ways:

Client-Side, through Javascript:

<script type="text/javascript">
    function SetContextKey()
    {
        $find('auJobs').set_contextKey('moo');
        return;
    }

</script>  `

or on the server side auJobs.ContextKey = "Whatever You need to put in here"

Terry