如何在按钮单击时刷新Web用户控件

时间:2013-07-25 05:43:04

标签: c# asp.net

我在aspx页面上使用web用户控件来显示google地图上的位置,我将位置作为ASPX页面加载事件的参数传递到每个页面加载时,我正在完美地获取位置。

每当用户在ASPX页面上单击“搜索”按钮搜索特定位置时,我必须更改位置,并且我在“搜索”按钮单击事件中将位置传递给Web用户控件但无法获取位置到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值变为Web用户控件的Mylocations值null ..所以有没有办法重新加载具有较新位置的用户控件。

1 个答案:

答案 0 :(得分:0)

我认为你可以在这里使用updatepanel。您必须将谷歌地图保留到更新面板,并将此按钮的触发器设置为您的地图。然后我想你会得到你想要的东西。如果有任何困惑请告诉我