我想在用户更改选择框中的值时显示 javascript 警报。这是我的代码,我做错了什么?
aspx
<asp:DropDownList ID="ddlGroups" AutoPostBack="true" runat="server" OnSelectedIndexChanged="ddlWagons_SelectedIndexChanged"></asp:DropDownList>
aspx.cs
protected void ddlWagons_SelectedIndexChanged(object sender, EventArgs e)
{
ClientScriptManager script = Page.ClientScript;
script.RegisterStartupScript(this.GetType(), "OpenWindowScript", "alert('Clicked')");
}
最佳答案
试试这个
添加
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
你的设计师部分
并在代码部分添加
var ID="Whatever the data is";
ClientScript.RegisterStartupScript(this.GetType(), "script", "alert('"+ID+"');", true);
如果您正在使用更新面板
试试这个
var ID="Whatever the data is";
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('"+ID+"');", true);
关于javascript - 在 asp.net webforms 方法中运行 javascript 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26991037/