Reputation: 1
I am facing issues when I tried to add same custom control twice in the same page. The issue is because instance of one control is caling the java script of the other. Added to that I am using ajax popup extender where in I have popup divs with in that control itself. Now it is leading to java script errors because it is geting confused among the popup div ids and scripts etc.
Please help me.
Upvotes: 0
Views: 1053
Reputation: 8389
Take one step further in taking care about client-side IDs generated uniquely for the tags inside each instance of your custom control.
This can be easily fixed by adding runat="server"
attributes to the tags which you want to have unique client side IDs when rendered to the browser. Then you should use this kind of code in JS:
document.getElementById("<%= control.ClientID %>");
As about tags which you don't want to mark using runat attribute, you can assign them their IDs uniquely on the server-side manually in each instance of the custom control.
I hope this helps!
Upvotes: 1
Reputation: 43158
There's no automatic fix for this. If a custom control is going to be used more than once on a page, you have to design it to be aware of this. In particular, you'll probably need to refer to generated elements using their generated id
:
var ele = document.getElementById("<%= serverSideControl.ClientID %>");
Javascript emitted by the control will have to also emit the appropriate ID's.
And so on.
Upvotes: 0