Two components with the same id 'id' can't be added to the application.

I have a large grid with 15 FilteredTextboxExtenders on each row. the amount of script generated to run on page load was creating a 15 second wait on page load. To eliminate this, I created this code:

<script type="text/javascript">
        function SetValidation(tb) 
        {
            try 
            {
                Sys.Application.add_init(function() {
                    $create(AjaxControlToolkit.FilteredTextBoxBehavior, { "ValidChars": "0123456789.", "id": tb.id + "_Validation" }, null, null, $get(tb.id));
                });
            }
            catch (ex) { }
        }
</script>
and for each grid control that was supposed to be validated, I added onfocus="SetVaidation(this);"
It worked, but if one control was focused twice, the following error would be generated: "Sys.InvalidOperationException: Two components with the same id 'id' can't be added to the application."
Even though I have a try catch block there, it still somehow stopped the updatepanel on the page from processing postbacks properly.
So, i need an If block to check if the component it's trying to "add to the application" is already there. I'm not sure where i need to look to find this..
something like:
If (!Components.Exists(id)) { //run code } 
 
0
colonel720
11/1/2008 11:19:34 PM
asp.net.ajax_control_toolkit 17816 articles. 1 followers. Follow

5 Replies
3601 Views

Similar Articles

[PageSpeed] 31
Get it on Google Play
Get it on Apple App Store

if ($get(tb.id + "_Validation") === null) { //attach behavior }


Cheers,
Jim Wang
Microsoft (ASP.NET)
http://weblogs.asp.net/jimwang
0
Jim
11/2/2008 12:11:14 AM

Jim Wang:

if ($get(tb.id + "_Validation") == null) { //attach behavior }

 

Thanks for your quick reply.

I tried that, and  $get(tb.id + "_Validation") was still null, even after the attach behavior script ran once.

0
colonel720
11/2/2008 12:31:39 AM

Anyone? this is kinda urgent, my client wants a demo tomorrow.

 If nobody can answer my question, how about pointing me to some resources on the javascript $get and $create methods so I can figure this out myself?

my google searches on $get and $create were no help.

 

Thanks

0
colonel720
11/2/2008 3:27:30 AM

Never mind, found the solution.

if (Sys.Application.findComponent(tb.id + "_Validation") == null) { }

0
colonel720
11/2/2008 3:48:31 AM

Sorry, yeah because it's a behavior it should have been $find instead of $get.  Glad you figured it out in time :).


Cheers,
Jim Wang
Microsoft (ASP.NET)
http://weblogs.asp.net/jimwang
0
Jim
11/2/2008 11:18:08 PM
Reply:

Similar Artilces:

UpdatePanel and custom Extender: 'two components with the same id can't be added to the application'
I am experiencing some strange behavior in my UpdatePanel which contains a ListView with a DataPager control. The items in the list view each have a custom ModalPopupExtender that is dynamically generated as well as a custom extender control that does some manipulation on an image.The first page of results loads correctly, and I can move to the next page fine as well. However, when I move back to the first page, Firebug shows me the 'two components with the same id can't be added to the application' exception thrown on each of the items on the first page of the list, on the behav...

Sys.InvalidOperationException: Two components with the same id 'x' can't be added to the application.
Hi. Firstly I am new to here and thanks for the answers. I am using ModalPopupExtender in my ASP.Net 2.0 User Control and it works as usual with Ajax. But when I click a node of a tree view control, an Ajax PostBack occurs and get the "Sys.InvalidOperationException: Two components with the same id 'x' can't be added to the application" and popup is unable to pop. It is a Javascript error. But no other Ajax PostBacks occur that error and if the AutoPostBack value of the treeView is false than no error occurs. x is the ID of the ModalPopupExtender and it's actual valu...

Sys.InvalidOperationException: Two components with the same id 'x' can't be added to the application.
Hi. Firstly I am new to here and thanks for the answers. I am using ModalPopupExtender in my ASP.Net 2.0 User Control and it works as usual with Ajax. But when I click a node of a tree view control, an Ajax PostBack occurs and get the "Sys.InvalidOperationException: Two components with the same id 'x' can't be added to the application" and popup is unable to pop. It is a Javascript error. But no other Ajax PostBacks occur that error and if the AutoPostBack value of the treeView is false than no error occurs. x is the ID of the ModalPopupExtender and it's actual v...

Sys.InvalidOperationException: Two components with the same id 'bsdate' can't be added to the application
 Hi I have a form that cotains various ajax controls 2 of which are calander extenders.It is a functional requirement that when a date is set in the start date field that the finish date field is set to the same date (if it does not yet contain a value) This is fine, and has bee implimented using the following client side script: function syncdate() { try { if($find('bedate').get_selectedDate() == null) { $find('bedate').set_selectedDate($find('bsdate').get_selectedDate()); } } catch(Except...

IE/JS Error: Two components with the same id 'RoundedCornersBehavior1' can't be added to the application
When I am creating two (or more) RoundedCornersExtender controls in the same page, the following IE/JS error is showing:Two components with the same id 'RoundedCornersBehavior1' can't be added to the application. My ASPX code is as below:   1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 2 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 4 5 <html xm...

Calendar Extender generates message "Sys.InvalidOperationException: Two components with the same id '{ExtenderId}' can't be added to the application error." when the container update panel is refreshe
Update Panel 1 contains an image button that triggers the refresh of a second update panel. The second panel contains a text box and a calendar extender. Both update panels have UpdateMode conditional. When the image button in update panel 1 triggers update panel 2, the message  Sys.InvalidOperationException: Two components with the same id '{ExtenderId}' can't be added to the application.  is generated. I am using AjaxControlToolkit release 10618.  Any ideas as to what might be happening or suggestions to work arond this issue?  Thanks in advance FJ &n...

Item has already been added. Key in dictionary: 'Id' Key being added: 'Id'
hi , when i am trying to delete a project from the project_list page i'm getting the following error : Item has already been added. Key in dictionary: 'Id'  Key being added: 'Id' can anybody help me ? thanks.Lebanese Please post your code. It will help us assess your issue.Ryan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to ask a question it's the time tracker starter kit code.Lebanese Charbel_Chalhoub wrote:it's the time tracker starter kit code. OK. Were you able to resolve it?Ryan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to a...

Please hekp, error: Item has already been added. Key in dictionary: 'id' Key being added: 'id'
I had that error before on FormView, I didn't find any solution, and managed to avoid that code. But now I really need a solution on this, please help. That happens when I reload page, on my page, my FormView is loaded dynamically, and that error happens on LoadControlState and LoadViewState,  in LoadControlState, it is on             if (objArray1[5] != null)            {                  Ord...

''''''''''''''''''''
Name: haznen Email: haznenatyahoodotcom Product: Gran Paradiso Alpha 8 Summary: '''''''''''''''''''' Comments: '''''''''''''''''''''''''''''''''''' Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061204 UGES/1.7.2.0 GranParadiso/3.0a1 From URL: http://www.mozilla.org/projects/granparadiso/ Note to readers: Hendrix gives...

Transforming 'plain' ID to 'adorned' ID
I must be missing something obvious here. Suppose I create an ASP.NET Web User Control, and I use a ModalPopupExtender inside it. In the ascx, I set various properties of the extender to refer to controls within the Web User Control, such as PopupDragHandleControlID="TitleText". At runtime, the control with ID "TitleText" gets a more complicated ID on the rendered page (call it an 'adorned' ID, not sure what the offical term is), such as "ctl00_ContentPlaceHolder1_MyCtrl1_TitleText". The behaviour javascript for the extender does things like - this._dragHandleElement = $get(this._PopupDrag...

Microsoft JScript runtime error: Sys.InvalidOperationException: Two components with the same id can't be added to the application
In my webpage I have an AJX accordian with one panel.  Inside this panel is a usercontrol containing some search logic and a grid.  When I select an item in the grid this triggers an event which is handled by the parent page.  The search logic and grid are inside an AJAX update panel set to update conditionally. The problem is when I select a grid item and the parent page reloads I get these javascript errors Microsoft JScript runtime error: Sys.InvalidOperationException: A control is already associated with the element.  Microsoft JScript runtime error: Sys.InvalidOpe...

[ID 20001130.012] Can't do '\'?
This is a bug report for perl from www@piranha.lhsc.on.ca, generated with the help of perlbug 1.26 running under perl 5.00503. ----------------------------------------------------------------- [Please enter your report here] A _very_ simple perl program: print '\'; causes "Can't find string terminator "'" anywhere before EOF at blah line 1." (test program saved as "blah") Could it be related to the fact that "'" used to be (?) synonymous with "::" in package names? ....Steve van der Burg s...

'do' won't 'do' if '/'
Greetings to All from Au, Have a NetWare Perl 5.8.4 and wanted to tweak File\Spec\NW.pm to try and standardise on '/' separators. If I run a test script (t/uni/lower.t) with an unmodified NW.pm, it calls t/uni/case.pl, that, in case.pl, (when the path separators are '\'), the $file is '..\lib\unicore\To\Lower.pl' and the following code portion works, with $simple getting a returned table: sub casetest { my ($base, $spec, $func) = @_; my $file = File::Spec->catfile(File::Spec->catdir(File::Spec->updir, "lib", &qu...

'''''
Name: mario Email: ramar17atfastwebnetdotit Product: Gran Paradiso Alpha 2 Summary: ''''' Comments: K: Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a2) Gecko/20070206 GranParadiso/3.0a2 ...

Web resources about - Two components with the same id 'id' can't be added to the application. - asp.net.ajax_control_toolkit

Resources last updated: 1/18/2016 8:45:36 AM