I don't have the if(!isPostBack) statement.
CS code behind:
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");
}
and the 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>
Im not sure if its about the first postback or because it take longer to load the page on the first time it loads.
The requestCompleted function is called a while after postback occurs which is why I have an update panel. I thought I had the update panel working, but now it only works on first time. Just incase you were wondering I did indeed try uncommenting the updatepanel.update() code but the same occurs. I put a break point in OnDataBind and it ONLY FIRES ON THE FIRST TIME. It won't fire any other time.
I AM NOT ABLE TO BIND DAT ON PAGE LOAD AS THE LIST HAS NOT BEEN POPULATED YET.