Solved

how do i get ajax toolkitscriptmanager to work with multiple controls

Posted on 2009-06-30
6
2,263 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

0
Comment
Question by:mjoseph23
  • 3
  • 3
6 Comments
 
LVL 20

Expert Comment

by:ddayx10
ID: 24750460
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)...
0
 

Author Comment

by:mjoseph23
ID: 24755762
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.
0
 
LVL 20

Accepted Solution

by:
ddayx10 earned 500 total points
ID: 24761737
Hmmm...If I understand you.

On your .aspx page you have the scriptmanager and a placeholder.

You are using the autocomplete extender with a textbox control.

You are loading multiple controls into the placeholder (starting with one and adding more).

Looks like you have a user control concept where it holds 1) textbox and 1) extendercontrol.

When you first load your page 1 of these controls comes with it. Then you fire some event and another control is added. These new usercontrols(containing your textbox and extender) are not functioning.

I have no idea if I have this right?! Depending on the scenario I dont think you need but 1 scriptmanager on the main page to make this work. No special settings are required on that scriptmanager.

I never really played with the autoextender before so I put together a sample that represents the page I described above. I can tell you are doing more (using a collapsible panel), and I likely dont have the scenario right, and I'm not sure how you're managing the state of dynamically added usercontrols (if you even are)...

For what it's worth this sample demonstrates that one scriptmanager can handle multiple dynamically loaded controls.
****ASPX Page****
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="autocompleteext.aspx.cs" Inherits="autocompleteext" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
		<asp:ScriptManager ID="sm" runat="server" />
		<div><asp:Button ID="btn1" runat="server" Text="Add Control" onclick="btn1_Click" /></div>	
		<asp:PlaceHolder ID="ph1" runat="server" />
    </form>
</body>
</html>
 
 
*****ASPX CODE BEHIND****
 
public partial class autocompleteext : System.Web.UI.Page
{
 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["noCtls"] = 0;
            AddControl();
        }
    }
 
    protected void btn1_Click(object sender, EventArgs e)
    {
        Session["noCtls"] = (int)Session["noCtls"] + 1;
        AddControl();
    }
 
    private void AddControl()
    {
        for (int i = 0; i <= (int)Session["noCtls"]; i++)
        {
            UserControl uc = new UserControl();
            uc = (UserControl)Page.LoadControl("~/usercontrols/autoExtender.ascx");
            ph1.Controls.Add(uc);
        }
    }
}
 
 
 
****ASCX PAGE****
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="autoExtender.ascx.cs" Inherits="usercontrols_autoExtender" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
 
<div>
<span>New Extender</span><br />
<asp:TextBox ID="txtAuto" runat="server" />
	
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
	 TargetControlID="txtAuto"
	 ServicePath="~/svc/WS.asmx"
	 ServiceMethod="GetSuggestions"
	 MinimumPrefixLength="1"
	 CompletionSetCount="12" />
 
</div>
 
****ASCX NEEDS NO CODE BEHIND****
 
 
****WEBSERVICE CLASS FILE****
using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Collections.Generic;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class WS : System.Web.Services.WebService {
 
    public WS () {}
 
    [WebMethod]
    public string[] GetSuggestions(string prefixText, int count)
    {
 
        List<string> responses = new List<string>();
 
        for (int i = 0; i < count; i++)
 
            responses.Add(prefixText + (char)(i + 65));
 
 
 
        return responses.ToArray();
 
    }
 
    
}

Open in new window

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:mjoseph23
ID: 24763754
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

0
 
LVL 20

Assisted Solution

by:ddayx10
ddayx10 earned 500 total points
ID: 24770993
--"well you have it right. but are you sure that the autocomplete extender is working on all controls for you? "

YES! I took the time to build the sample (and understand what you were communicating), of course I tested it. I put it up there for you to test as well...and if you had you wouldn't be asking me that question.

Sorry if that's a little short tempered, it's late, I'm tired, and that is frustrating.

Start stripping back the functional of your site or build a sample model on the side. Either way I suspect your problem has something to do with either the way you are manipulating the IDs or your JavaScript handling from the first post is messing things up. It may also be that you are using an older version of the AJAXToolkit that has a bug (I have found them before). Starting with something simpler and moving forward until it breaks will help you find where your problem is...there is no magic bullet here it seems. Without full samples of your source code I really can't be more specific than that. Even if I had them I would be doing pretty much the same thing I just suggested you do :)

It's late, long weekend ahead, hope you make progress, I'll check back on you next week.
0
 

Author Comment

by:mjoseph23
ID: 24788596
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.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question