警报在 UpdatePanel 中不起作用 VB.Net
Alert not working in UpdatePanel VB.Net
这是我试过的。
ASPX 文件:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button OnClick="btnOK1_Click" ID="btnOK1" runat="server" Text="Save" />
</ContentTemplate>
</asp:UpdatePanel>
ASPX.VB:
Protected Sub btnOK1_Click(sender As Object, e As EventArgs)
Dim alertMsg As String
Dim alertScript As String
alertMsg = String.Format("You Selected {0}", "My Message")
alertScript = String.Format("<script type= text/javascript>alert('{0}');</script>", alertMsg)
ClientScript.RegisterStartupScript(Me.[GetType](), "Alert", alertScript)
End Sub
当我从后端单击按钮(保存)时,我试图获得一个带有消息的警告框。我尝试了 Whosebug 的解决方案。但是,这些代码无法让我获得 javascript 警告框。该事件触发良好并贯穿代码。有人帮我解决这个问题吗?
replace your code with these
Protected Sub btnOK1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim alertMsg As String
Dim alertScript As String
alertMsg = String.Format("You Selected {0}", "My Message")
alertScript = String.Format("<script type='text/javascript'>alert('{0}');</script>", alertMsg)
ScriptManager.RegisterStartupScript(Page, Page.GetType, "Alert", alertScript, False)
End Sub
问题似乎在于您使用的是 ClientScript
而不是 ScriptManager
。
ClientScript
用于同步回发,而 ScriptManager
用于异步。
有关详细信息,请参阅 this question。
这是我试过的。
ASPX 文件:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button OnClick="btnOK1_Click" ID="btnOK1" runat="server" Text="Save" />
</ContentTemplate>
</asp:UpdatePanel>
ASPX.VB:
Protected Sub btnOK1_Click(sender As Object, e As EventArgs)
Dim alertMsg As String
Dim alertScript As String
alertMsg = String.Format("You Selected {0}", "My Message")
alertScript = String.Format("<script type= text/javascript>alert('{0}');</script>", alertMsg)
ClientScript.RegisterStartupScript(Me.[GetType](), "Alert", alertScript)
End Sub
当我从后端单击按钮(保存)时,我试图获得一个带有消息的警告框。我尝试了 Whosebug 的解决方案。但是,这些代码无法让我获得 javascript 警告框。该事件触发良好并贯穿代码。有人帮我解决这个问题吗?
replace your code with these
Protected Sub btnOK1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim alertMsg As String
Dim alertScript As String
alertMsg = String.Format("You Selected {0}", "My Message")
alertScript = String.Format("<script type='text/javascript'>alert('{0}');</script>", alertMsg)
ScriptManager.RegisterStartupScript(Page, Page.GetType, "Alert", alertScript, False)
End Sub
问题似乎在于您使用的是 ClientScript
而不是 ScriptManager
。
ClientScript
用于同步回发,而 ScriptManager
用于异步。
有关详细信息,请参阅 this question。