2013-07-25 38 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