use usercontrol more than once in one page - problem
Hi everybody,
We have the following scenario:
A usercontrol/macro which generats some HTML (with some specific ids and javascript). If this usercontrol is used in the page once - it works
Now i just added the same usecontrol/macro on another position of the same page template and now each id exist more than once and javascript does not know which id it has to show.
So now my question is how to solve this problem. We have to generate all the HTML only once. I just thought about looking in the usercontrol if the id of the div still exists and only generate the html if it does not exist.
but if the user is on another page and opens the usercontrol it should be opened. Is this working with guids? Or does it store the information in session or cookie?
The solution is a better design ! If you are using Jquery and selectors, do not rely on ids ! Unique IDs are only generated for server controls :
<div id="myid"></div> => will be rendered multiple times with the same id
<div id="myid" runat="server"></div> : id will be recreated by the server.
To access your id in your javascript. IF it's on the usercontrol use $('#<%=myid.ClientID%>) or ClientId ? I never know :-) If not you need to passe the id somehow to your external JS
use usercontrol more than once in one page - problem
Hi everybody,
We have the following scenario:
A usercontrol/macro which generats some HTML (with some specific ids and javascript). If this usercontrol is used in the page once - it works
Now i just added the same usecontrol/macro on another position of the same page template and now each id exist more than once and javascript does not know which id it has to show.
So now my question is how to solve this problem. We have to generate all the HTML only once. I just thought about looking in the usercontrol if the id of the div still exists and only generate the html if it does not exist.
Is there any other solution for it?
use guids / add the usercontrols clientid to each id.
but if the user is on another page and opens the usercontrol it should be opened. Is this working with guids? Or does it store the information in session or cookie?
Thanks
The solution is a better design ! If you are using Jquery and selectors, do not rely on ids ! Unique IDs are only generated for server controls :
<div id="myid"></div> => will be rendered multiple times with the same id
<div id="myid" runat="server"></div> : id will be recreated by the server.
To access your id in your javascript. IF it's on the usercontrol use $('#<%=myid.ClientID%>) or ClientId ? I never know :-) If not you need to passe the id somehow to your external JS
is working on a reply...