Solved

ScriptManager.RegisterClientScriptBlock not working

Posted on 2011-03-06
5
1,130 Views
Last Modified: 2012-05-11
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
Comment
Question by:scm0sml
5 Comments
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 35046596
0
 

Author Comment

by:scm0sml
ID: 35046627
what has he done differently to what I am doing?
0
 
LVL 16

Expert Comment

by:BurnieP
ID: 35046858
Hi,

Try RegisterStartupScript insead :

ScriptManager.RegisterStartupScript(Me.Page, Me.GetType, "DisplayAlertaj", script, True);
0
 
LVL 19

Accepted Solution

by:
Albert Van Halen earned 500 total points
ID: 35047224
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
 

Author Comment

by:scm0sml
ID: 35198539
I know have:
Dim script = ""
            script += "DisplayAlert('" & message & "')"            
            ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType, "DisplayAlertAJ", script, True)

which works fine.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question