当用户在选择框中更改值时,我想显示一个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);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句