We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

how do i get ajax toolkitscriptmanager to work with multiple controls

mjoseph23
mjoseph23 asked
on
Medium Priority
2,595 Views
Last Modified: 2012-05-07
I have a control that uses the autocomplete extender on a textbox. You need a scriptmanager for it to work. When I put the toolkitscriptmanager on the page using the controls the autocomplete extender works for the first control, but all controls other than the first do NOT work. So I tried taking the toolkitscriptmanager off the aspx page and put it on the actual control page (ascx) and I got the following error - Only one instance of script manager can be added to the page. I am stuck
Control
 
            SubSet:<asp:TextBox ID="tbSubset" CssClass="textbox" runat="server" TextMode="SingleLine"
                AutoPostBack="true" ontextchanged="tbSubset_TextChanged"></asp:TextBox>
            <!--<asp:HiddenField ID="hdSubSet" runat="server" />-->
            <asp:HiddenField ID="hdSubSetTime" runat="server" />
            <cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="tbSubset"
                BehaviorID="AutoCompleteEx" ServiceMethod="Get_SubSet_List" UseContextKey="false"
                ServicePath="Web_Services/LookupSubSet.asmx" MinimumPrefixLength="1" CompletionInterval="1000"
                EnableCaching="true" CompletionSetCount="20" DelimiterCharacters=";, :" OnClientItemSelected="itemSelected"
                CompletionListCssClass="completion_list">
            </cc1:AutoCompleteExtender>
            <%-- Prevent enter in textbox from causing the collapsible panel from operating --%>
 
            <script type="text/javascript">
            // Work around browser behavior of "auto-submitting" simple forms
            var frm = document.getElementById("aspnetForm");
 
            if (frm) 
            {
                frm.onsubmit = function() { return false; };
            }
                                            
            function itemSelected(source, eventArgs)
            {
                //alert("key: " + eventArgs.get_text() + "  value: " + eventArgs.get_value());
                //document.all["hdSubset"].value = eventArgs.get_text();
                document.all["hdSubSetTime"].value = eventArgs.get_value();
                //__doPostBack('hidButton','AutoCompleteItemSelected'); 
                document.forms[0].hidButton.click();
            }
            </script>
 
toolkitscriptmanager on aspx page
 
    <cc1:ToolkitScriptManager  runat="server" EnablePartialRendering="true" EnablePageMethods="true"
        ID="ToolkitScriptManager1" EnableScriptGlobalization="true" />

Open in new window

Comment
Watch Question

Commented:
Likely should have worked with the scriptmanager from "Ajax Extensions" (default tab name) on the page that is calling the control, but obviously it didnt. One scriptmanager will handle all controls on a page, if you run into a scenario where you have a scriptmanager on a page (master or page w/controls) and it is not being detected then try putting the scriptmanager on the page and a scriptmanagerproxy on the child (in your case the control)...

Author

Commented:
toolkitscriptmanager is the ajax scriptmanager. i tried with the scriptmanager on (aspx )page and proxy on child control page (ascx) i don't know what attributes i should have for the proxy though. i don't think i was clear enough on what i meant by "controls" I have a placeholder that can have multiple controls of the same type. and the main problem is when the aspx page loads the placeholder loads the first control. the autocompleteextender works for the first control. when i click add another control of the same type the autocomplete extender does not work for the second or any other but the first control. to resolve this problem i tried to take the toolkitscriptmanager off the (aspx page) and put on the (ascx page) that throws the "only one instance of scriptmanager can be added to the page" error. so its looking like the only way this will work is when i have the script manager on the (aspx) page like you said and change some other settings somewhere.
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
well you have it right. but are you sure that the autocomplete extender is working on all controls for you? ( if you have two controls does it work on the 2nd as well as the first?) i am able to load as many controls that i want but for some odd reason. the lookup list is only firing for the first control.
    private void Add_OR_Items()
    {
        foreach (string ctl in Page.Request.Form)
        {
            if (ctl == "btnAddORItem")
            {
                ctlCount2.Value = (Convert.ToInt16(ctlCount2.Value) + 1).ToString();
            }
        }
 
        // clear all dropdown and textbox controls
        phORItems.Controls.Clear();
 
        int controlId = 1;
 
        for (int i = 0; i < Convert.ToInt16(ctlCount2.Value); i++)
        {
            ASP.uc_ORItem myUserControl = (ASP.uc_ORItem)LoadControl("uc_ORItem.ascx");
 
            while (InDeletedList2("ucORItem" + controlId.ToString()))
            {
                controlId += 1;
            }
 
            myUserControl.ID = "ucORItem" + controlId.ToString();
            //use this line anywhere on the container page to hook the UserControl's TextBox exposed using the TotalTextBox Property
            myUserControl.QuantityTextBox.TextChanged += new EventHandler(tbQuantity2_TextChanged);
            myUserControl.RemoveUserControl += new EventHandler(HandleRemoveUserControl2);
            phORItems.Controls.Add(myUserControl);
            controlId += 1;
        }
    }

Open in new window

Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
OK. I created a sample website and compared my attributes with yours and found that I was setting the BehaviorID="AutoCompleteEx" and by removing that it now works.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.