2013-07-25 37 views
0

我在aspx页面上使用web用户控件来显示google地图上的位置,我将位置作为参数从ASPX页面加载事件和每次加载页面传递到I我完美地获取位置。如何刷新按钮点击Web用户控件

我必须更改位置,每当用户搜索特定位置点击ASPX页面上的“搜索”按钮时,我将位置传递给“搜索”按钮点击事件中的网络用户控件,但无法获取到Web用户控件的位置。

public partial class MapControl : System.Web.UI.UserControl 
{ 
    public List<string> MyLocation {get; set; } 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     GeoCode geocode; 
     List<GMarker> markers = new List<GMarker>(); 
     for (int i = 0; i < MyLocation.Count(); i++) 
     { 
      geocode = GMap1.getGeoCodeRequest(MyLocation[i]); 
      GLatLng gLatLng = new GLatLng(geocode.Placemark.coordinates.lat, geocode.Placemark.coordinates.lng); 
      GMap1.setCenter(gLatLng, 20, GMapType.GTypes.Normal); 
      GMarker oMarker = new GMarker(gLatLng); 
      markers.Add(oMarker); 
      //GMap1.Add(oMarker); 
      GListener listener = new GListener(oMarker.ID, GListener.Event.click, string.Format(@"function() {{ var w = new google.maps.InfoWindow(); w.setContent('<center>{0}</center>'); w.open({1}, {2});}}", "<b>" + MyLocation[i] + "</b>", GMap1.GMap_Id, oMarker.ID)); 
      GMap1.Add(listener); 
     } 

     GMap1.Add(new GMapUI()); 
     GMap1.GZoom = 10; 

protected void Button1_Click1(object sender, EventArgs e) 
    { 
List<string> locations = new List<string>(); 
       for (int i = 0; i < ListView1.Items.Count; i++) 
       { 
        Label addressline1 = (Label)this.ListView1.Items[i].FindControl("addr1"); 
        string addrloc = addressline1.Text; 
        locations.Add(addrloc); 
       } 
       MapControl mc = LoadControl("~/MapControl.ascx") as MapControl; 
       mc.MyLocation = locations; 
} 

而我包括在此web用户控件到Search.aspx文件,当我通过从页面加载事件其工作地点,但是当我试图通过从搜索按钮单击事件越来越Null值的位置分成Mylocations的价值Web用户控制为空..所以有什么办法来重新加载用户控件与新的位置。

+0

你可以发布我们的代码?并且在页面加载事件中使用“ispostback” – Backtrack

+0

您到目前为止尝试解决您的问题。 –

回答

0

我想你可以在这里使用updatepanel。您必须将Google地图保留在更新面板中,并将触发按钮设置为您的地图。那我想你会得到你想要的。如果有任何困惑请让我知道

+0

嗨, 感谢您的答复我已经保持谷歌地图在一个网络用户控制和正如你所说我保持更新面板中的用户控制也与触发器一起,但我无法通过此按钮上的Web用户控件中的位置点击..就好像我们看到asp页面生命周期事件**控件事件**将在页面的** Load **事件后触发,以便在按钮单击事件之前加载用户控件并阻止我传递位置值...有没有什么办法来加载用户控件后按钮点击更新的值 – user1203530

+0

[link](http://stackoverflow.com/questions/14207174/load-user-control-dynamically-on-button-click) – 2013-07-26 07:08:08

+0

http://stackoverflow.com/questions/14207174/load-user-control-dynamically-on-button-click转到此链接。这可能对你有所帮助。 – 2013-07-26 07:09:36