Checking if Startup Script is already executed
Posted on 2010-09-01
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.