未在pageload?上调用Javascript代码。网
我目前正试图在更新面板刷新时调用JavaScript函数,但由于某些原因,它没有被调用;尽管我使用的方法与其他函数完全相同 c#,这在页面加载事件中:未在pageload?上调用Javascript代码。网,javascript,.net,Javascript,.net,我目前正试图在更新面板刷新时调用JavaScript函数,但由于某些原因,它没有被调用;尽管我使用的方法与其他函数完全相同 c#,这在页面加载事件中: ScriptManager.RegisterStartupScript( UpdatePanel1, this.GetType(), "Modify Map", "modifyMap();",
ScriptManager.RegisterStartupScript(
UpdatePanel1,
this.GetType(),
"Modify Map",
"modifyMap();",
true);
Javascript函数:
function modifyMap() {
alert(1);
//To change the map size if the user is viewing the site on a mobile.
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
//Change width/height of map.
//Change the width of the wrapper to 100% of the screen.
document.getElementById('wrapper-div').style.width = "100%";
//Set the map to fill the wrapper.
document.getElementById('canvasMap').style.width = "100%";
//Set the height of the map.
document.getElementById('canvasMap').style.height = "500px";
}
}
如果有人能帮我,那就太好了
谢谢
Callum添加一个onload事件,例如:
window.onload = modifyMap;
不要把它放在函数中。我总是把它放在脚本关闭标记的前面
您还可以将onload事件添加到HTML标记中
<body onload="modifyMap()">
尝试在预渲染中注册脚本,同时尝试重命名密钥(不带空格)
protected void Page_PreRender(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(
UpdatePanel1,
this.GetType(),
"ModifyMapKey",
"modifyMap();",
true);
}