Last post Dec 28, 2008 07:30 AM by HeartattacK
Dec 28, 2008 06:42 AM|flashb|LINK
i want to user this script to display an message box:
If (Not aspxPage.ClientScript.IsStartupScriptRegistered(strKey)) Then
aspxPage.ClientScript.RegisterStartupScript(aspxPage.GetType, strKey, strScript)
Can someone explain me how the KEY Parameter works and what it does? When i use always the same key what happens? And, when should i use different keys?
Dec 28, 2008 07:07 AM|lionscub|LINK
Picture the scripts you register with ClientScript.RegisterStartupScript (or RegisterClientScript) as sitting in a dictionary. Each entry has a key and a value. You should always use a different key unless you are overwriting a previously reigstered script.
Dec 28, 2008 07:30 AM|HeartattacK|LINK
If you have a function, say mycoolfn(), then you'd want to register that only once. In that case, you specify a specific key (like "cool"). Then, no matter how many times you register it, only the first one will stay. Now, say you have a call to a function,
like "alert('hello');". You want this to run everytime you register it. In that case, you'd use a unique key. If an already used key is used, the new call will not get registered.
Btw...if you have asp.net AJAX support (doesn't mean you have to use it or have a scriptmanager on the page, if your server supports it), you should be using:
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), key, script, addTags);