3 回答

TA贡献1785条经验 获得超8个赞
从我的头顶上:
使用GetType()而不是typeof(Page)为了将脚本绑定到您的实际页面类而不是基类,
传递键常量而Page.UniqueID不是,因为它应该由命名控件使用,所以它没有什么意义,
以分号结束Javascript语句,
在此PreRender阶段注册脚本:
protected void Page_PreRender(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, GetType(), "YourUniqueScriptKey",
"alert('This pops up');", true);
}

TA贡献1783条经验 获得超4个赞
试试这个代码...
ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "script", "alert('Hi');", true);
哪里UpdatePanel1是id为Updatepanel您的网页上

TA贡献1825条经验 获得超4个赞
如果导致脚本的控件位于updatepanel内部,则必须将updatepanel id放在第一个参数中,否则使用关键字“ this”代替更新面板,此处为代码
ScriptManager.RegisterStartupScript(UpdatePanel3, this.GetType(), UpdatePanel3.UniqueID, "showError();", true);
添加回答
举报