remove a script registered with RegisterStartupScript

G

Guest

Hi all,
Is there any way to replace a script I registered in Page Load with the
method Page.RegisterStartupScript
 
K

Kevin Spencer

This question is a bit confusing. The RegisterStartupScript method takes a
string and adds it to the page as a startup script, by inserting it at the
bottom of the form. You say you want to "replace" it. Now, as it is only
"placed" when you call the method, all you have to do is use a different
script string when you call the method. Assuming you only call the method
one time, and pass only one string to it, whichever string you pass to it
will be the one placed in the Page.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
 
G

Guest

Actually this's not exactly what happens when u call the
RegisterStartupScript twice.
If u called it twice, only the first call will appear. the second one (which
is intended to replace the first one) won't be registered when the same key
is used.

I found another work around for my problem, but I am really interested to
find a solution for this problem.
 
K

Kevin Spencer

I didn't say to call it twice. You only need to call it once. Why on earth
would you want to have your app execute an instruction that you don't intend
for it to follow? That is what you're asking. In essence, you are saying, "I
tell my app to insert this script, and I want to know how to tell it
afterwards to insert a different script, rather than the one I already told
it to insert." Instead, you should determine which script you really want to
insert, and tell it to insert that one. Once.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
 
D

drea

I actually do want to know how to replace the script, and call it again
with a different tagname. So if someone has a solution to this I would
love to hear it.

Andrea
 
D

drea

I actually do want to know how to replace the script, and call it again
with a different tagname. So if someone has a solution to this I would
love to hear it.

Andrea
 

ZLA

Joined
Jul 18, 2006
Messages
2
Reaction score
0
While I understand that method was designed to only be called once, I would like to know how to accomplish the following without having to call the script twice or adding complex code.

Consider a user control which contains server controls which have to be initialized by javascript via a Startup script during the user control's Page Load event.

Now assume that user control is contained in a panel which is made invisible after the startup script has already been created. The user control will not appear on the page and its controls won't exist. The startup script will now throw errors.

Of course, its possible to write the startup script to check for existence of its own objects first. However, wouldn't it be nice if we didn't have to send all that useless client side script to the user when the panel is invisible? It would be great if the user control could have a public method / property (perhaps overriding the Visible property) which would allow us to erase the original startup script.

I'd like to hear Kevin Spencer's approach on this situation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top