ClientScript parm definitions

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
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?
 
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.
 
Back
Top