views:

230

answers:

1

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  A: 

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.

ybo
Can you show me a sample code about it please?
mavera