Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1135
  • Last Modified:

ScriptManager.RegisterClientScriptBlock not working

As you can see in my function below, I did use ClientScript.RegisterClientScriptBlock and it worked fine.

I have now added an update panel to one of my pages so need this javascript alret function to work in there so have created an ajax version.

What do I need to do to:
ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType, "DisplayAlertaj", script, True)

As it isn't currently doing anything?

Thanks in advance
Public Sub JavascriptAlertAjax(ByVal message As String)
        Try
            Dim script = "<script language='JavaScript'> "
            script += "DisplayAlert('" & message & "')"
            script += "</script>"
            'ClientScript.RegisterClientScriptBlock(Me.GetType, "DisplayAlert", script)
            ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType, "DisplayAlertaj", script, True)
        Catch ex As Exception
            Throw
        End Try
    End Sub

Open in new window

0
scm0sml
Asked:
scm0sml
1 Solution
 
Rajkumar GsSoftware EngineerCommented:
0
 
scm0smlAuthor Commented:
what has he done differently to what I am doing?
0
 
BurniePCommented:
Hi,

Try RegisterStartupScript insead :

ScriptManager.RegisterStartupScript(Me.Page, Me.GetType, "DisplayAlertaj", script, True);
0
 
Albert Van HalenCommented:
The last parameter (addScriptTags) is set to true; it appends script-tags to your script.
Since you have it already in your string you can set it to false or you could remove the script tags from the string.

I would remove the script tags from the string...
Public Sub JavascriptAlertAjax(ByVal message As String)
        Try
            Dim script = "DisplayAlert('" & message & "')"
            ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType, "DisplayAlertaj", script, True)
        Catch ex As Exception
            Throw
        End Try
    End Sub

Open in new window

0
 
scm0smlAuthor Commented:
I know have:
Dim script = ""
            script += "DisplayAlert('" & message & "')"            
            ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType, "DisplayAlertAJ", script, True)

which works fine.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now