asp.net 回发后未呈现的文本控件



我正在尝试使用谷歌地图来显示从数据库中提取的一些位置。这是自动售货点的所有列表,由一组促销员分组,在选择促销员后,必须显示在地图上。 成功使用 Subgurim.net 库后,我决定在 https://www.codeproject.com/Articles/36151/Show-Your-Data-on-Google-Map-using-C-and-JavaScrip 的帮助下转向Javascript实现(唯一的区别是我使用的是GoogleMaps v3调用)。 javascript 插入在页面加载时效果很好,但是当我需要在启动器代码上回发以显示他的自动售货点时,我可以在代码中看到文本控件中加载的数据,但没有标记呈现在网页上。如果我使用 Edge 的开发工具检查正在生成的页面Microsoft我总是发现文本控件替换为在第一次(无回发)页面加载期间加载的数据。 页面的 aspx 部分非常简单,它不包含在 UpdatePanel 中,尽管页面上使用了 UpdatePanel,并且我也尝试在文本控件上使用 EnableViewState true 和 false,没有变化。

这是 aspx 相关部分:

<div id="mapContent" >
<asp:Literal ID="mapJs" runat="server" EnableViewState="false" />
<div id="mapDiv" style="width:100%; height:640px;" />
<div id="infoDiv">
....
</div>
</div>

这是插入脚本第一部分的代码部分:

StringBuilder map = new StringBuilder();
bool loadPVGiro = false;
double centerMapLat = 37.451669,
centerMapLong = 15.05263;
map.Append(@"<script type='text/javascript'>" + System.Environment.NewLine);
map.Append("var map;" + System.Environment.NewLine);
map.Append("function infoCallback(infowindow, marker)" + System.Environment.NewLine);
map.Append("{" + System.Environment.NewLine);
map.Append("  return function()" + System.Environment.NewLine);
map.Append("  {" + System.Environment.NewLine);
map.Append("    infowindow.open(map, marker);" + System.Environment.NewLine);
map.Append("  };" + System.Environment.NewLine);
map.Append("}" + System.Environment.NewLine);
map.Append("function mapLoad()" + System.Environment.NewLine);
map.Append("{" + System.Environment.NewLine);
map.Append("var centralPoint = { lat: " + centerMapLat.ToString().Replace(",", ".") + ", lng: " + centerMapLong.ToString().Replace(",", ".") + "};" + System.Environment.NewLine);
map.Append("var map = new google.maps.Map(document.getElementById('mapDiv'), { zoom: 12, center: centralPoint });" + System.Environment.NewLine);
map.Append("}" + System.Environment.NewLine);   // mapLoad close
map.Append("</script>" + System.Environment.NewLine);
map.Append("<script async defer src="https://maps.googleapis.com/maps/api/js?key=MY_GOOGLE_MAPS_API_KEY&callback=mapLoad"> " + System.Environment.NewLine);
map.Append("</script> " + System.Environment.NewLine);
mapJs.Text = map.ToString();

这是呈现页面的部分(来自 Edge 的开发工具):

<div id="mapContent" >
<script type='text/javascript'>
var map;
function infoCallback(infowindow, marker)
{
return function()
{
infowindow.open(map, marker);
};
}
function mapLoad()
{
var centralPoint = { lat: 37.451669, lng: 15.05263};
map = new google.maps.Map(document.getElementById('mapDiv'), { zoom: 12, center: centralPoint });
}
</script>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=MY_GOOGLE_MAPS_API_KEY&callback=mapLoad"> 
</script> 
<div id="mapDiv" style="width:100%; height:640px;" />
....

发生回发时,在选择启动器代码后,脚本将使用标记列表完全重新生成,并且文本控件由新脚本填充(我只能通过断点看到它),但页面上的控件仍然是第一个。显然,如果我在第一页加载期间强制使用代码,则所有标记都会正确显示。 脚本中的 infoCallback 函数仅用于强制为地图上放置的每个标记生成新的 InfoWindow。 任何帮助将不胜感激。

鲁道夫。

PS:也尝试在文字控件上使用 ViewStateMode="disabled",没有更改。

PS2>尝试了ClientScript.RegisterClientScriptBlock和ClientScript.RegisterStartupScript,但生成的脚本与文字控件完全相同。忘了提到实际页面在母版页内。

该问题似乎与更新面板中的用户树有关;单击用户会生成回发,但文本控件中注入的脚本永远不会在页面上更新,只会在代码隐藏中更新。删除更新面板,脚本将正确更新和执行。完成项目所需的修改后,我将尝试进一步调查此行为。

最新更新