I need to execute javascript before Page load in ASP.NET application.
My function returns user location, and I would like to pass value to server side and load data based on location.
The problem is javascript function executes after page load.
Here is my code:
$(function () {
getLocation();
});
in getLocation function I set hidden field value
$("#<%= HfLocation.ClientID %>").val(location);
in code behind I try to get value but it's always empty
protected void Page_Load(object sender, EventArgs e)
{
var location = HfLocation.Value;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…