C# 如何在执行c方法之前运行javascript函数

C# 如何在执行c方法之前运行javascript函数,c#,javascript,jquery,asp.net,C#,Javascript,Jquery,Asp.net,我最近几天面临这个问题。。。需要专家建议 我试图在代码隐藏中从URL读取查询字符串值。如果查询字符串可用,那么我需要对其进行地理编码。这个函数在同一个.aspx页面上 该函数将从google获取geocodeLAT,LNG,并将其分配给页面上可用的隐藏变量。之后,我需要运行我的c代码,然后获得LAT、LNG值,并进入数据库查找最近的商店 页面加载 你的责任是复杂的。服务器端代码与客户端代码紧密耦合。。因为它们试图同时执行相同的功能。您应该将服务器端代码移动到某种描述的web服务中,然后执行客户端

我最近几天面临这个问题。。。需要专家建议

我试图在代码隐藏中从URL读取查询字符串值。如果查询字符串可用,那么我需要对其进行地理编码。这个函数在同一个.aspx页面上

该函数将从google获取geocodeLAT,LNG,并将其分配给页面上可用的隐藏变量。之后,我需要运行我的c代码,然后获得LAT、LNG值,并进入数据库查找最近的商店

页面加载
你的责任是复杂的。服务器端代码与客户端代码紧密耦合。。因为它们试图同时执行相同的功能。您应该将服务器端代码移动到某种描述的web服务中,然后执行客户端与服务交互的其余工作。您是否尝试过使用ScriptManager.RegisterClientScriptBlock而不是ScriptManager.RegisterStartupScript。@Simon:您能给我举个例子吗…@Neelam:我尝试过,但没有成功…您是否尝试过使用:Page.ClientScript.RegisterStartupScript GetType,GeoCodeAddress,codeAddress+qsText.Value+;,符合事实的
protected void Page_Load(object sender, EventArgs e)
{
    _queryStringVal = Request.QueryString["k"];
    string eventTarget = Request["__EVENTTARGET"];
    string eventArgument = Request["__EVENTARGUMENT"];
    if (!Page.IsPostBack)
    {
      if (!String.IsNullOrEmpty(_queryStringVal))
      {
        qsText.Value = _queryStringVal;
        BindListView();
      }
    }
    else
    {
      if (!String.IsNullOrEmpty(eventArgument) || !String.IsNullOrEmpty(eventTarget))
      {
        Lat = Convert.ToDouble(eventTarget);
        Long = Convert.ToDouble(eventArgument);
        BindListView();
      }
    }
}

protected void BindListView()
{
    var parameter = _queryStringVal;

    if (!string.IsNullOrEmpty(parameter))
    {
      ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert", "<script type='text/javascript'>alert('hello');</script>", true);
      //ScriptManager.RegisterStartupScript(this, GetType(), "GeoCodeAddress", "codeAddress(" + qsText.Value + ");", true);
    }

    Lat = Convert.ToDouble(currentLat.Value); // this is where error occurs because the value is NULL
    Long = Convert.ToDouble(currentLong.Value);

  if ((Lat == 0.00) || Long == 0.00)
    {
          ShowErrorPanel();
          return;
    }
}
$(document).ready(function () {
    var param = getParameterByName("k"); // function to get querystring param
    if (param.length > 1) {
          codeAddress(param);
    }
});

function codeAddress(addressToGeoCode) {
    var geocoder = new window.google.maps.Geocoder();
    geocoder.geocode({ 'address': addressToGeoCode }, function (results, status) {
      if (status == window.google.maps.GeocoderStatus.OK) {
            var firstLoc = results[0].geometry.location;
            lathv.val(firstLoc.lat());
            lnghv.val(firstLoc.lng());
            PageRedirect();
      }
      else {
            console.log('No results found: ' + status);
      }
    });
}

function PageRedirect() {
    //window.location.href = window.location.href.split('?')[0] + "?k=" + $('.AddressSearch').val();
   __doPostBack(lathv.val(), lnghv.val());
}