How to programmatically set the ContextKey of an AutoComplete Extender placed in a gridviews footer

Posted by rism on Stack Overflow See other posts from Stack Overflow or by rism
Published on 2010-06-17T20:29:55Z Indexed on 2010/06/17 20:33 UTC
Read the original article Hit count: 918

As per the thread title I want to programmatically set the ContextKey of an AutoComplete Extender placed in a gridviews footer row.

Background is I have a data model that has Territory and Journey Plans for those territories. Customers need to be added to the journey plans but only those customers that belong to the Territory that owns the Journey Plan.

In the footer row of my grid I have added a textbox which allows a user to enter account code of customer. Attached to this textbox is an autocomplete extender. I need to do a select against the db for customers with account code like prefix where customer in territory.

But there is no way to provide territory id. I thought I could just:

<asp:TemplateField HeaderStyle-Width="100" HeaderStyle-HorizontalAlign="Left" HeaderText="LKey"
                        ItemStyle-HorizontalAlign="Left" ItemStyle-Width="100">
                        <ItemTemplate>
                            <asp:Label ID="lblLKey" runat="server" Text='<%# Eval("LKey") %>' />
                        </ItemTemplate>
                        <FooterTemplate>
                            <asp:TextBox ID="txtLKey" CssClass="sitepagetext" runat="server" MaxLength="15" Width="60" />
                            <cc1:AutoCompleteExtender ID="Autocompleteextender1" MinimumPrefixLength="4" CompletionInterval="1000"
                CompletionSetCount="10" ServiceMethod="GetCompletionList" ContextKey="<% this.Controller.TerritoryId %>"
                TargetControlID="txtLKey" runat="server">
            </cc1:AutoCompleteExtender>
                        </FooterTemplate>
                    </asp:TemplateField>

for the relevant field in the grid but when the page is run I get the following markup for the autoextender:

Sys.Application.add_init(function() {
    $create(AjaxControlToolkit.AutoCompleteBehavior, {"contextKey":"\u003c% this.Controller.TerritoryId %\u003e","delimiterCharacters":"","id":"ctl00_ctl00_mainContentHolder_serviceContentHolder_qlgvJourneyPlanCustomers_ctl03_Autocompleteextender1","minimumPrefixLength":4,"serviceMethod":"GetCompletionList","servicePath":"/Views/CRM/JourneyPlans/CustomersEditor.aspx","useContextKey":true}, null, null, $get("ctl00_ctl00_mainContentHolder_serviceContentHolder_qlgvJourneyPlanCustomers_ctl03_txtLKey"));
});
//]]>
</script>

ContextKey value doesnt get evaluated. It just uses the literal text.

Any thoughts?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about autocompleteextender