Writing single client script block for mutiple controls

J

Jason Barnett

I'm using .NET 1.1 and I've created a server control that writes javascript
to the output writer. The control works great, except when I add additional
controls. The problem is that each control writes the same javascript block,
which causes a stack overflow when it is executed.

Could someone tell me how I may write the javascript to the page only once,
regardless of how many controls are dropped on the web form?
 
N

Nathan Sokalski

In the RegisterClientScriptBlock method, what are you using as the key (the
first parameter)?
 
J

Jason Barnett

I'm not using the RegisterClientScriptBlock method. From what I've read,
that is a method on the ClientScriptManager class and is only available in
..NET 2 or higher. Is there something comparable in .NET 1.1?

I'm currently writing the script as plain text using output.Write method
within the Render method.
 
J

Jason Barnett

Ok, I now see where I made one mistake. I did a search on
RegisterClientScriptBlock and found that it is a method on the Page class
(although, it does not appear in intellisense). I modified my code to use
the RegisterClientScriptBlock method in conjunction to the
IsClientScriptBlockRegistered method, but multiple blocks are still being
written to the page.

I'm using a constant as the key (ex: "MyClientScript").
 
J

Jason Barnett

I am starting to wonder if the problem lies within the script block itself...
here is an example of what I'd like written out only once. Does it matter
that it is linked to an external .js file?

<script src="javascrip/myControl.js" type="text/javascript"></script>
 
J

Jason Barnett

Ok, I got it. I was trying to use the RegisterClientScriptBlock method
during the Render event. When I used it during the PreRender event it began
working.
 
S

sam

Watch out for this method. After 8 different calls it will start
outputing the script tags in a random order with respect to what order
the method executes in the page. this is because microsoft uses the
retarded HybridDictionary class.

Should'nt make a difference unless you require the script tags to be
output in a specific order.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top