Jqmodal 在更新面板中不起作用

发布于 2024-07-15 06:02:46 字数 814 浏览 6 评论 0原文

我有一个名为 raise_alarm() 的方法,它显示一个基于 jquery 的消息框。 但是,当我从 Updatepanel 内部的控件(例如提交按钮)的事件调用此方法时,它不起作用。 相关代码如下。 我该如何修复它?

 Public Sub Raise_Alarm(ByVal p_Page As Page, ByVal p_Message As String, Optional ByVal p_IsError As Boolean = True)
        Dim strScript As String
        strScript = "$(function() { Mesaj('" & p_Message & "'); });" & ControlChars.NewLine
        p_Page.ClientScript.RegisterStartupScript(p_Page.GetType(), "alert", strScript, True)
end sub

Private Sub dtlQuestion_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dtlQuestion.ItemCommand
        If Not User.Identity.IsAuthenticated Then
            Raise_Alarm(Me, "Giriş Yapmadan Oy Veremezsiniz")
            Exit Sub
        End If
end sub

I have a method named raise_alarm() which, show a message box based on jquery. But when I call this method from an event of a control(such as submit button) which is inside of Updatepanel, it isn't working. Related codes are below. How can I fix it?

 Public Sub Raise_Alarm(ByVal p_Page As Page, ByVal p_Message As String, Optional ByVal p_IsError As Boolean = True)
        Dim strScript As String
        strScript = "$(function() { Mesaj('" & p_Message & "'); });" & ControlChars.NewLine
        p_Page.ClientScript.RegisterStartupScript(p_Page.GetType(), "alert", strScript, True)
end sub

Private Sub dtlQuestion_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dtlQuestion.ItemCommand
        If Not User.Identity.IsAuthenticated Then
            Raise_Alarm(Me, "Giriş Yapmadan Oy Veremezsiniz")
            Exit Sub
        End If
end sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云朵有点甜 2024-07-22 06:02:46

您必须使用 ScriptManager 而不是 p_Page.ClientScript

编辑:示例。 我在代码中用 ScriptManager 替换了 p_Page.ClientScript

Public Sub Raise_Alarm(ByVal p_Page As Page, ByVal p_Message As String, Optional ByVal p_IsError As Boolean = True)
        Dim strScript As String
        strScript = "$(function() { Mesaj('" & p_Message & "'); });" & ControlChars.NewLine
        ScriptManager.RegisterStartupScript(p_Page.GetType(), "alert", strScript, True)
end sub

Private Sub dtlQuestion_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dtlQuestion.ItemCommand
        If Not User.Identity.IsAuthenticated Then
            Raise_Alarm(Me, "Giriş Yapmadan Oy Veremezsiniz")
            Exit Sub
        End If
end sub

ClientScript 不支持 ajax,ScriptManager 知道如何处理部分回发。 请快速浏览一下 msdn 上的这篇文章

You have to use ScriptManager instead of p_Page.ClientScript.

EDIT : Example. I replaced p_Page.ClientScript by ScriptManager in your code.

Public Sub Raise_Alarm(ByVal p_Page As Page, ByVal p_Message As String, Optional ByVal p_IsError As Boolean = True)
        Dim strScript As String
        strScript = "$(function() { Mesaj('" & p_Message & "'); });" & ControlChars.NewLine
        ScriptManager.RegisterStartupScript(p_Page.GetType(), "alert", strScript, True)
end sub

Private Sub dtlQuestion_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dtlQuestion.ItemCommand
        If Not User.Identity.IsAuthenticated Then
            Raise_Alarm(Me, "Giriş Yapmadan Oy Veremezsiniz")
            Exit Sub
        End If
end sub

ClientScript is not ajax enabled, ScriptManager knows how to deal with partial postbacks. Please have a quick look at this article on msdn.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文