我在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用戶控制爲空..所以有什麼辦法來重新加載用戶控件與新的位置。
你可以發佈我們的代碼?並且在頁面加載事件中使用「ispostback」 – Backtrack
您到目前爲止嘗試解決您的問題。 –