Link to home
Start Free TrialLog in
Avatar of jvoconnell
jvoconnell

asked on

Checking if Startup Script is already executed


Experts,

I am new to ASP.NET and I am just looking to gain an understanding on something. I've searched around but I can't find anything that answers my question completely.

In my ASP.NET application I want to display an alert box to the user if there is an error. In my Catch Block I have the line of code below and it works.

Page.ClientScript.RegisterStartupScript(Me.GetType(), "error", "alert('" & ex.Message & "');", True)


From what I've read, it says you should call the IsStartupScriptRegistered method to determine whether a startup script with a given key and type pair is already registered and avoid unnecessarily attempting to add the script.


I've seen exampes where the IsStartupScriptRegistered method is used in an IF statement and if the script isn't registered then the line of code I'm already using will be executed. But what I cant find is how to handle situations where the script is already registered. (How do I get my alert box to display?...what would be the syntax I use then?)

What is the downside of RegisterStartupScript multiple times?

Maybe I'm overthinkng this. But any input is greatly appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Luis Pérez
Luis Pérez
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jvoconnell
jvoconnell

ASKER

Hi Roland,  I apologize for the late response. Something unexpectedly came up and I was away. I can use your answer to accomplish what I need to do.  Thank you very much and once again, I'm sorry for taking so long to respond.