Jqmodal isn't working in the Updatepanel

╄→гoц情女王★ 提交于 2019-12-12 01:17:48

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/646140/jqmodal-isnt-working-in-the-updatepanel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!