簡體   English   中英

回發后未呈現asp.net文字控件

[英]asp.net literal control not rendered after postback

我正在嘗試使用Google Maps來顯示從數據庫中提取的一些位置。 這是自動販賣點的清單,按一組啟動子分組,選擇啟動子后,必須在地圖上顯示。 在成功使用Subgurim.net庫之后,我決定借助https://www.codeproject.com/Articles/36151/Show-Your-Data-on-Google-Map-using- C和JavaScrip (唯一的區別是我正在使用GoogleMaps v3調用)。 javascript插入在頁面加載時效果很好,但是當我需要在啟動程序代碼上回發以顯示他的自動售貨機時,我可以在代碼隱藏中看到文字控件中加載的數據,但是網絡上沒有呈現標記頁。 如果我使用Microsoft Edge的開發工具檢查正在生成的頁面,則總是會發現文字控件被在第一次(無回發)頁面加載期間加載的數據替換。 頁面的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,但是生成的腳本與文字控件完全相同。 忘了提到實際頁面在MasterPage內部。

問題似乎與更新面板中的用戶樹有關。 單擊用戶會生成一個回發,但是文字控件中注入的腳本永遠不會在頁面上更新,而只會在后面的代碼中更新。 刪除updatepanel腳本已正確更新並執行。 完成項目所需的修改后,我將嘗試進一步研究這種行為。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM