Hi i wanted to know is it possible to call a codebehind function in my Javascript? The javascript is in the head of my asp.net webpage page.
I have tried many methods but none seem to have worked. Its the first time iv had to do this so an example would be a nice learning curve fix.
My codebehind function in C#
protected void GetAverageRent_TextChanged(object sender, EventArgs e)
{
string Postcode = _postCodeInput.Value.ToString();
var webGet = new HtmlWeb();
var doc = webGet.Load("http://www.webadress.com/" + Postcode);
HtmlNode AvgPrice = doc.DocumentNode.SelectSingleNode("//div[@class='split2r right']//strong[@class='price big']");
if (AvgPrice != null)
{
AverageRentLbl.Text = AvgPrice.InnerHtml.ToString();
}
else
{
AverageRentLbl.Text = "Invalid Postcode!";
AverageRentLbl.ForeColor = Color.Red;
AverageRentLbl.Font.Bold = true;
}
}
My Javascript
<script>
function codeAddress() {
document.getElementById('map-canvas').setAttribute("style", "height:200px");
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
zoom: 16,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
//var address = document.getElementById('_mainContentHolder__postCodeValue').value;
var address = document.getElementById('ContentPlaceHolder1__postCodeInput').value;
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
document.getElementById('ContentPlaceHolder1__latValue').value = results[0].geometry.location.lat();
document.getElementById('ContentPlaceHolder1__longValue').value = results[0].geometry.location.lng();
} else {
alert('Sorry the postcode you entered in invalid. Please try again: ' + status);
document.getElementById('ContentPlaceHolder1__postCodeInput').value = "";
}
});</Script>