Solved

ScriptManager.RegisterClientScriptBlock not working

Posted on 2011-03-06
5
1,131 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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