emitting client script

J

JV

I'm aware of RegisterClientScriptBlock and RegisterStartupScript, but ....

Suppose you need to execute some script code when your page loads....perhaps
you need to call an Init() function and pass it a reference to your control.
Of course you can emit a client script for the OnLoad event of the page, but
there are problems with that:
(1) if there's already an OnLoad script on the page, then only the
last one will actually be executed (I tested this out in HTML with multiple
OnLoad scripts)
(2) if you have more than one instance of your control on a form, and
the Init() function needs to be called once for each control instance, now
you have to figure out how to APPEND script code to the OnLoad script.
Don't see any way to make that work.

And, of course, individual elements like <table> don't fire OnLoad so you
can't just hook those. Oh they fire some other event like that, but only
when they have a behavior assigned to them. Not too useful here.

I'm sure this has to be a common problem in developing custom web controls.
Has someone devised a means to do it?
 
J

JV

As far as I can determine, the "key" parameter is nothing more than a
hashtable key. In other words, it is intended to uniquely identify a
particular script block ...which is useful for determining if it has already
been registered. But it has no effect of tying that script to a particular
control.

Currently I use RegisterStartupScript to call some Init code on my custom
grid. So I emit the following script:
<SCRIPT LANGUAGE="javascript" type="text/javascript">
<!--
var oGrid = document.all("myNewGrid1");
Grid_Init(oGrid);
// -->
</SCRIPT>

where "Grid_Init" is a previously declared javascript function.
Unfortunately, though I've tested that "oGrid" refers to the right tag, the
call still throws an error claiming I have left off a semicolon.
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top