我有一个JS函数。当我从链接按钮调用它时,它工作得很好。但当我从后端调用它时,错误是函数未定义。为什么会发生这种情况?我需要先在Pageload事件中注册它,然后再在所需的函数中注册吗?此LOC位于所需的函数中。我没有在Pageload中注册脚本,因为我不需要它。
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), script, "displayGrade(); ", true);
if(!ClientScript.IsClientScriptBlockRegistered(script))
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), script, "displayGrade(); ", true);我的脚本函数只有一行
<script>
function displayGrade()
{
document.getElementById('idGrade').style.display = 'block';
}
发布于 2018-06-12 10:37:38
我将div设为server元素,现在我不需要javascript就可以从后台代码中更改div的属性。
C#:
int level = TreeMenuView1.SelectedNode.Depth;
if(level==0)
{div1.Style.Add("display", "block");}https://stackoverflow.com/questions/50808023
复制相似问题