ClientScript parm definitions

G

Guest

hey all,

can someone please explain in lamen's terms the following:
ClientScript.RegisterStartupScript(this.GetType(), "key2", "javascript
string", true);
what does this.GetType() mean?
what is the key2 parm used for?

thanks,
rodchar
 
G

George Ter-Saakov

Just imagine scenario you have a user control on the page.
And that user control is trying to add JavaScript function MyFunction to the
page.

so it's using RegisterScript.....

Now if you have 2 same user controls on the page. both of them will try to
add MyFunction to the page... Which is sort of a mistake. You will duplicate
definition.

So the right way to do it will be check if that function already exists or
not. That why we have "key2". ASP.NET gives you way to check is that script
already been added to the page.
-----------------------------------

now what happens if two different controls starting using same name "key2".
The get all confused. So ASP.NET gives you Type parameter. So they will not
mix.

Sort of like namespace.

George.
 
G

Guest

i see GetType( ) a lot in intellisense for a lot of objects. is the reasoning
you gave the same for others that have the GetType( ) method?
 
G

George Ter-Saakov

in .NET all objects are derived from System.Object

System.Object has several methods and GetType is one of them.
so naturally it will come up in intellisense.

It' just returns a "type" of that particular object.

George.
 

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,009
Latest member
GidgetGamb

Latest Threads

Top