我正在 .cs 页面中使用此脚本..
public void messagebox(string msg)
{
Label lbl = new Label();
lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "')</script>";
Page.Controls.Add(lbl);
}
错误为
无法修改 Controls 集合,因为该控件包含代码块(即 <% ... %>)。
最佳答案
要注册脚本,请使用 ScriptManager
ScriptManager.RegisterStartupScript(this, this.GetType(), "registeredAlert", lbl, false);
关于c# - 添加 javascript 进行控制时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5884305/