我没有if(!isPostBack)语句。
CS代码背后:
private void TestPlacesApi()
{
GeoRequest request = new GeoRequest("LU7 0JX");
GeoResponse response = request.GetResponse();
if (response.Status == GeoStatus.ZERO_RESULTS) return;
GeoLocation location = response.Results[0].Geometry.Location;
double latitude = location.Latitude;
double longitude = location.Longitude;
var placesWebReq = new GPlacesWebRequest
{
Latitude = latitude.ToString(),
Longitide = longitude.ToString(),
Radius = "7500",
Types = "restaurant",
Sensor = "false"
};
var url = placesWebReq.GetWebUrlString();
HttpWebRequest webRequest = WebRequest.Create(@url) as HttpWebRequest;
webRequest.Timeout = 20000;
webRequest.Method = "GET";
webRequest.BeginGetResponse(new AsyncCallback(RequestCompleted), webRequest);
}
private void RequestCompleted(IAsyncResult result)
{
var request = (HttpWebRequest)result.AsyncState;
var response = (HttpWebResponse)request.EndGetResponse(result);
var s = response.GetResponseStream();
RootObjectPlaces place;
using (var stream = response.GetResponseStream())
{
var r = new StreamReader(stream);
var resp = r.ReadToEnd();
place = new RootObjectPlaces();
JsonConvert.PopulateObject(resp, place);
}
List<GLocatedRestaurant> restaurantList = new List<GLocatedRestaurant>();
foreach (var theplace in place.Results)
{
restaurantList.Add(new GLocatedRestaurant
{
Icon = theplace.Icon,
Name = theplace.Name,
Opening_hours = theplace.Opening_hours,
Photos = theplace.Photos,
Price_level = theplace.Price_level,
Types = theplace.Types,
Vicinity = theplace.Vicinity,
Rating = theplace.Rating,
// Address = Util.GetAddressFromGeometry(theplace.Geometry.Location)
}
);
}
this.RestaurantRepeater.DataSource = restaurantList;
RestaurantRepeater.DataBind();
//UpdatePanel1.UpdateMode = UpdatePanelUpdateMode.Conditional;
//UpdatePanel1.Update();
}
protected void onDataBind(object sender, RepeaterItemEventArgs e)
{
Util.trace("HAHAHA");
}
和aspx:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Repeater ID="RestaurantRepeater" OnItemDataBound="onDataBind" runat="server">
<ItemTemplate>
<div runat="server" id="restaurantsList">
<div class="restaurantListing" id='restaurantListing'>
<img class='restaurantImage' src='<%# DataBinder.Eval(Container.DataItem, "Icon")%>' />
<div class="restaurantRightInfo" id='restaurantRightInfo'>
<%# DataBinder.Eval(Container.DataItem, "Address")%><br />
</div>
<div class="ratingInfo" id='ratingInfo'>
<%# DataBinder.Eval(Container.DataItem, "Name")%><br />
<%# DataBinder.Eval(Container.DataItem, "Opening_hours")%><br />
<%# DataBinder.Eval(Container.DataItem, "Rating")%><br />
<%# DataBinder.Eval(Container.DataItem, "Vicinity")%><br />
</div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
我不确定它是关于第一次回发还是因为第一次加载时加载页面需要更长时间。
在回发发生后调用requestCompleted函数,这就是我有更新面板的原因。我以为我有更新面板工作,但现在它只适用于第一次。 只是因为你想知道我确实尝试取消注释updatepanel.update()代码,但同样的情况也是如此。我在OnDataBind中设置了一个断点,它只在第一次发生。它不会在任何其他时间开火。
我无法在页面加载时绑定DAT,因为该列表尚未被广泛使用。