ClientScript.RegisterClientScriptBlock in ASP.NET 2.0

Discussion in 'ASP .Net Building Controls' started by Nathan Sokalski, Jul 3, 2006.

  1. I am working on converting my code from ASP.NET 1.1 to ASP.NET 2.0. In
    ASP.NET 1.1 the RegisterClientScriptBlock method was just a key and script
    (2 Strings), but in ASP.NET the ClientScript.RegisterClientScriptBlock also
    includes a parameter called 'type' which is of Type. This sounds like it is
    supposed to specify whether the script is JavaScript, VBScript, JScript,
    ECMAScript, etc., but I what am I supposed to enter here (I have not heard
    of a value of Type that would specify this)? (I always use JavaScript for my
    client-side scripts) Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
    Nathan Sokalski, Jul 3, 2006
    #1
    1. Advertising

  2. Hi Nathan,

    Try it like this:

    ClientScript.RegisterStartupScript(Me.GetType, "Startup",
    scriptString)


    Ken
    Microsoft MVP [ASP.NET]

    "Nathan Sokalski" <> wrote in message
    news:...
    >I am working on converting my code from ASP.NET 1.1 to ASP.NET 2.0. In
    >ASP.NET 1.1 the RegisterClientScriptBlock method was just a key and script
    >(2 Strings), but in ASP.NET the ClientScript.RegisterClientScriptBlock also
    >includes a parameter called 'type' which is of Type. This sounds like it is
    >supposed to specify whether the script is JavaScript, VBScript, JScript,
    >ECMAScript, etc., but I what am I supposed to enter here (I have not heard
    >of a value of Type that would specify this)? (I always use JavaScript for
    >my client-side scripts) Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    Ken Cox [Microsoft MVP], Jul 3, 2006
    #2
    1. Advertising

  3. Nathan Sokalski

    daniel # Guest

    Hi Nathan

    RegisterClientScriptBlock doesn't know about client side scripting, the
    parameter type is the object 'type', You usually get this with GetType()
    method.

    See ya
    daniel #

    "Nathan Sokalski" <> wrote in message
    news:...
    >I am working on converting my code from ASP.NET 1.1 to ASP.NET 2.0. In
    >ASP.NET 1.1 the RegisterClientScriptBlock method was just a key and script
    >(2 Strings), but in ASP.NET the ClientScript.RegisterClientScriptBlock also
    >includes a parameter called 'type' which is of Type. This sounds like it is
    >supposed to specify whether the script is JavaScript, VBScript, JScript,
    >ECMAScript, etc., but I what am I supposed to enter here (I have not heard
    >of a value of Type that would specify this)? (I always use JavaScript for
    >my client-side scripts) Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    daniel #, Jul 3, 2006
    #3
  4. The C# flavor would be:

    ClientScript.RegisterStartupScript(typeof(this), "Startup",
    scriptString)

    I was hoping an MVP would say why they decided to associate scripts with the
    pages that contain them; I'm assuming that the same script manager object is
    shared throughout the web site.

    "Nathan Sokalski" wrote:

    > I am working on converting my code from ASP.NET 1.1 to ASP.NET 2.0. In
    > ASP.NET 1.1 the RegisterClientScriptBlock method was just a key and script
    > (2 Strings), but in ASP.NET the ClientScript.RegisterClientScriptBlock also
    > includes a parameter called 'type' which is of Type. This sounds like it is
    > supposed to specify whether the script is JavaScript, VBScript, JScript,
    > ECMAScript, etc., but I what am I supposed to enter here (I have not heard
    > of a value of Type that would specify this)? (I always use JavaScript for my
    > client-side scripts) Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    >
    >
    William Sullivan, Jul 3, 2006
    #4
  5. William, its just to give you a much better option to identifying script
    files. Basically if you just provided a key string, this will surely make it
    unique but if the key was associated to a particular control, it wont clash
    with other controls that might be using the same key to identify their
    scripts, since now my key is prefixed to my control.

    Specially if you are a control author, this is useful since I dont know what
    kind of key the end user might want to use to uniquely identify his other
    script files. I dont want to assume what it might be either, so if i can
    prefix this with the type of my control i have a better chance of making the
    key unique and avoid any un-necessary clashes or limiting the end user. I
    guess you can consider specfying a type as providing a namespace.

    This is also hinted in the documentation :
    "A client script is uniquely identified by its key and its type. Scripts
    with the same key and type are considered duplicates"


    Regards,
    Alessandro Zifiglio
    http://www.AsyncUI.net
    "William Sullivan" <> ha scritto
    nel messaggio news:...
    > The C# flavor would be:
    >
    > ClientScript.RegisterStartupScript(typeof(this), "Startup",
    > scriptString)
    >
    > I was hoping an MVP would say why they decided to associate scripts with
    > the
    > pages that contain them; I'm assuming that the same script manager object
    > is
    > shared throughout the web site.
    >
    > "Nathan Sokalski" wrote:
    >
    >> I am working on converting my code from ASP.NET 1.1 to ASP.NET 2.0. In
    >> ASP.NET 1.1 the RegisterClientScriptBlock method was just a key and
    >> script
    >> (2 Strings), but in ASP.NET the ClientScript.RegisterClientScriptBlock
    >> also
    >> includes a parameter called 'type' which is of Type. This sounds like it
    >> is
    >> supposed to specify whether the script is JavaScript, VBScript, JScript,
    >> ECMAScript, etc., but I what am I supposed to enter here (I have not
    >> heard
    >> of a value of Type that would specify this)? (I always use JavaScript for
    >> my
    >> client-side scripts) Thanks.
    >> --
    >> Nathan Sokalski
    >>
    >> http://www.nathansokalski.com/
    >>
    >>
    >>
    Alessandro Zifiglio, Jul 3, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sck10
    Replies:
    7
    Views:
    7,435
    Steven Cheng[MSFT]
    Nov 17, 2005
  2. =?Utf-8?B?bWFj?=

    Remove clientscript block from page (ASP.NET 1.1)

    =?Utf-8?B?bWFj?=, Jun 13, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    5,891
    Jacob
    Jun 20, 2006
  3. Nathan Sokalski
    Replies:
    4
    Views:
    60,999
    Alessandro Zifiglio
    Jul 3, 2006
  4. Stan SR
    Replies:
    3
    Views:
    709
    Laurent Bugnion, GalaSoft
    Oct 6, 2006
  5. Scott M.
    Replies:
    2
    Views:
    1,353
    bruce barker
    Sep 9, 2008
Loading...

Share This Page