473,467 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Why doesn't Google Map in User control work for multtiple instances?

4 New Member
Hi,
I have created user control which contains google map .
code in user control is as follows
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="javascript">
  2. var map;
  3. fucntion intialize(){
  4.   map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
  5.  
  6.         //set the default center
  7.        map.setCenter(myLatlng);
  8.         //set the default zoom
  9.        map.setZoom(initialZoom);
  10.  
  11.         //Set the map type
  12.        map.setMapTypeId(google.maps.MapTypeId.SATELLITE);
  13. }
  14. </script>
HTML code:
Expand|Select|Wrap|Line Numbers
  1. <div id="map_canvas" style="float: left; width: 100%; height: 300px; border: solid 1px black;" > </div>
Call to Initialize() function is from code behind(.ascx.cs) using
Me.Page.ClientScript.RegisterStartupScript(Me.GetT ype(), "FunctionCall", "initialize();")

Everythings works fine when single instance for user control is used in parent page (.aspx page).
But when I tried to used this user control multiple times in page ,only map for 1st instance is showing. But for other instances it is not showing anything but blank

I want to display google maps for all instances of the user control
For ex when user control is used 4 times,4 maps should be displayed

Thanks & Regards,
Anirudha Deshpande
Feb 9 '11 #1
5 2668
Frinavale
9,735 Recognized Expert Moderator Expert
In HTML, every element (<div>s etc.) must have a unique ID.

So, your HTML is not valid when you have multiple User Controls, each with a <div> that has an ID of "map_canvas". This means that your JavaScript is not going to work (because there are multiple <div> elements with the same ID...so the document.getElementById method won't work).

To fix this, use a Panel.
A Panel is rendered as a <div> element. ASP.NET ensures that each Panel is given a unique Client-ID so that it produces valid HTML.

Now, the trick is knowing what IDs are assigned to the Panels when they are rendered as <div> elements.

You can use the Panel.ClientID property to access the ID that is assigned to the <div> element when the Panel is rendered.

You can either register an Array of ClientIDs with the ScriptManager (or with your page)...or you can register a JavaScript method-call with the ScriptManager/Page that calls the "initialize" JavaScript method....and you can pass the ClientID as a parameter into the "initialize" JavaScript method.

-Frinny
Feb 9 '11 #2
anirudha d
4 New Member
Hi frinny,
Thank you very much for the reply.
i tried of taking panel instead of div.but its not working .When I put Runat="Server" ,its giving javascript null object error.
Feb 11 '11 #3
Frinavale
9,735 Recognized Expert Moderator Expert
It would really help if you posted some code so that I can see what you're doing now.

:)
Feb 11 '11 #4
NitinSawant
270 Contributor
dude, try this
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="javascript">
  2. var map_<%=this.ClientID%>;
  3. fucntion intialize_<%=this.ClientID%>(){
  4.   map_<%=this.ClientID%> = new google.maps.Map(document.getElementById("<%=map_canvas.ClientID%>"), mapOptions);
  5.  
  6.         //set the default center
  7.        map_<%=this.ClientID%>.setCenter(myLatlng);
  8.         //set the default zoom
  9.        map_<%=this.ClientID%>.setZoom(initialZoom);
  10.  
  11.         //Set the map type
  12.        map_<%=this.ClientID%>.setMapTypeId(google.maps.MapTypeId.SATELLITE);
  13. }
  14. </script>
  15.  
Expand|Select|Wrap|Line Numbers
  1. <div id="map_canvas" runat="server" style="float: left; width: 100%; height: 300px; border: solid 1px black;" > </div>
  2.  
Best of luck,

Regards,
Nitin
Feb 12 '11 #5
NitinSawant
270 Contributor
don't forget to call the initialize function,

Expand|Select|Wrap|Line Numbers
  1. intialize_<%=this.ClientID%>();
  2.  
Feb 12 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jim M | last post by:
I finally got a user control working that has a HTML drop down list. The user control is held in a simple parent test page. The onchange is set to call a javascript function DropChanged() which...
1
by: TIM T | last post by:
I want to load a user control from a dll dynamically to my main form. I have been reading about using reflection. I got this to work with the methods from my other classes in the dll but I am not...
3
by: Vivek Sharma | last post by:
Hi, I have created a dropdownlist as a web user control. I am using its multiple instances on the webpage. How do I access the selectedValue of each instance? All the instances have different...
3
by: Ant | last post by:
I'm building a Web user control that has several public functions. Can I fire them from the client side? for example Javascript and an HTML button
5
by: Doug Handler | last post by:
Hi, I have a form (Form1) that contains a tab control which one tab has a customer user control (UserControl1). When the user double-clicks on the grid hosted there a new user control is...
0
by: mivhaelveloz | last post by:
Hiya Im trying to get a user control working in mono/ASP.NET. ....I have no problem getting a basic control up and working and using it declaratively in a hosting page's .aspx file. But for...
4
by: | last post by:
I'm building some user controls. I very much like how you can build custom properties to be bound to a user control, and how instances of that control will show those custom properties in the...
1
by: James Geurts | last post by:
I'm having some major problems trying to get a user control working in asp.net 2.0. I have a user control in a sub directory of my project and I'm attempting to put it on an aspx page. I'm...
7
by: | last post by:
I have what's probably a simple page lifecycle question related to dynamically evaluating values that are placed by a repeater and dynmically placing user controls that use those values. I'm...
0
by: Eniac | last post by:
Hi, I've been working on a custom user control that needs to be modified and the validation is causing me headaches. The control used to generate a table of 4 rows x 7 columns to display all...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.