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
George Ter-Saakov - 15 Oct 2007 16:09 GMT
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.
> hey all,
>
[quoted text clipped - 6 lines]
> thanks,
> rodchar
rodchar - 15 Oct 2007 17:20 GMT
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?
> Just imagine scenario you have a user control on the page.
> And that user control is trying to add JavaScript function MyFunction to the
[quoted text clipped - 29 lines]
> > thanks,
> > rodchar
George Ter-Saakov - 15 Oct 2007 17:54 GMT
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.
>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?
rodchar - 17 Oct 2007 17:00 GMT
thank you for making it pretty clear for me, i appreciate the effort.
rod.
> in .NET all objects are derived from System.Object
>
[quoted text clipped - 8 lines]
> >reasoning
> > you gave the same for others that have the GetType( ) method?