Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Error Use of unassigned local variable 'ClientScript'

Error Use of unassigned local variable 'ClientScript'

Scheduled Pinned Locked Moved ASP.NET
questionhelp
16 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Md Marufuzzaman

    I want to popup an aspx page from a function using the following code..            string strScript = null; ClientScriptManager ClientScript; strScript = "window.open('popupContent.aspx','new_Win','height=650,width=250,resizable=0')"; ClientScript.RegisterClientScriptBlock(this.GetType(), "popup", strScript, true); But it's not allow me to compile..showing that Error Use of unassigned local variable 'ClientScript'     How can i resolve this? Thanks Md. Marufuzzaman

    A Offline
    A Offline
    Abhishek Sur
    wrote on last edited by
    #6

    Rather than using RegisterClientScriptBlock, it is better to use RegisterStarupScript use

    if(!this.ClientScript.IsClientScriptBlockRegistered("myscript"))
    this.ClientScript.RegisterStartupScript(this.GetType(), "myscript", strScript , true);

    Hope this helps. :rose:

    Abhishek Sur


    My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

    **Don't forget to click "Good Answer" if you like to.

    M 1 Reply Last reply
    0
    • M Manas Bhardwaj

      Zoki Manas wrote:

      ClientScriptManager ClientScript = Page.ClientScript;

      Why to create a new object unnecesarily ? Btw, I noticed your last name is Manas. :) In Hindi, it means some one who is very close to heart. What does it mean in your language?

      Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #7

      Manas Bhardwaj wrote:

      it means some one who is very close to heart

      :rose: :jig: ;)

      Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

      1 Reply Last reply
      0
      • A Abhishek Sur

        Rather than using RegisterClientScriptBlock, it is better to use RegisterStarupScript use

        if(!this.ClientScript.IsClientScriptBlockRegistered("myscript"))
        this.ClientScript.RegisterStartupScript(this.GetType(), "myscript", strScript , true);

        Hope this helps. :rose:

        Abhishek Sur


        My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

        **Don't forget to click "Good Answer" if you like to.

        M Offline
        M Offline
        Md Marufuzzaman
        wrote on last edited by
        #8

        Thanks.. Could you please tell me why RegisterStarupScript is better rather then the RegisterClientScriptBlock

        I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.


        Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. Thanks Md. Marufuzzaman

        A A 2 Replies Last reply
        0
        • M Md Marufuzzaman

          Thanks.. Could you please tell me why RegisterStarupScript is better rather then the RegisterClientScriptBlock

          I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.


          Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. Thanks Md. Marufuzzaman

          A Offline
          A Offline
          Abhijit Jana
          wrote on last edited by
          #9

          Make sure one things : if you have AJAX Script Manager in your page, then you have to use ScriptManager rather than ClientScript. :)

          Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

          M 1 Reply Last reply
          0
          • A Abhijit Jana

            Make sure one things : if you have AJAX Script Manager in your page, then you have to use ScriptManager rather than ClientScript. :)

            Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

            M Offline
            M Offline
            Md Marufuzzaman
            wrote on last edited by
            #10

            Thanks for sharing...:)

            I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.


            Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. Thanks Md. Marufuzzaman

            1 Reply Last reply
            0
            • M Manas Bhardwaj

              Zoki Manas wrote:

              ClientScriptManager ClientScript = Page.ClientScript;

              Why to create a new object unnecesarily ? Btw, I noticed your last name is Manas. :) In Hindi, it means some one who is very close to heart. What does it mean in your language?

              Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

              J Offline
              J Offline
              J4amieC
              wrote on last edited by
              #11

              Manas Bhardwaj wrote:

              Why to create a new object unnecesarily ?

              There's no object created there... just a reference to one which already exists on the Page class.

              1 Reply Last reply
              0
              • M Manas Bhardwaj

                Zoki Manas wrote:

                ClientScriptManager ClientScript = Page.ClientScript;

                Why to create a new object unnecesarily ? Btw, I noticed your last name is Manas. :) In Hindi, it means some one who is very close to heart. What does it mean in your language?

                Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

                N Offline
                N Offline
                N a v a n e e t h
                wrote on last edited by
                #12

                Manas Bhardwaj wrote:

                Why to create a new object unnecesarily ?

                There is no harm in doing so.

                Navaneeth How to use google | Ask smart questions

                1 Reply Last reply
                0
                • M Md Marufuzzaman

                  Thanks.. Could you please tell me why RegisterStarupScript is better rather then the RegisterClientScriptBlock

                  I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.


                  Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. Thanks Md. Marufuzzaman

                  A Offline
                  A Offline
                  Abhishek Sur
                  wrote on last edited by
                  #13

                  Yes... RegisterStartupScript places the script after all the objects are rendered while RegisterClientScriptBlock places the JS at the beginning. Thus say you are calling a javascript using RegisterClientScriptBlock which gets an element, you will find this null, as the script gets executed just before any html is rendered. In case of RegisterStartupScript the script is placed after the html is generated. So If you want to place a javascript call in your html, always use RegisterStartupScript. Hope you got it. If not I can give you examples. :)

                  Abhishek Sur


                  My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

                  **Don't forget to click "Good Answer" if you like to.

                  M 1 Reply Last reply
                  0
                  • M Manas Bhardwaj

                    Zoki Manas wrote:

                    ClientScriptManager ClientScript = Page.ClientScript;

                    Why to create a new object unnecesarily ? Btw, I noticed your last name is Manas. :) In Hindi, it means some one who is very close to heart. What does it mean in your language?

                    Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

                    A Offline
                    A Offline
                    Abhishek Sur
                    wrote on last edited by
                    #14

                    Hey manas, as everybody else suggested... Referring to a variable to the same object doesnt actually create a variable. Rather it just places the pointer to the same variable if the reference is derived from Object. If its Value Types this would be different. Thus ClientScriptManager ClientScript = Page.ClientScript ClientScript.RegisterClientScriptBlock is same as Page.ClientScript.RegisterScriptBlock

                    Manas Bhardwaj wrote:

                    In Hindi, it means some one who is very close to heart. What does it mean in your language?

                    :-D In my language it means "Worship to God" :-D :-D . Cheers. :rose:

                    Abhishek Sur


                    My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

                    **Don't forget to click "Good Answer" if you like to.

                    1 Reply Last reply
                    0
                    • A Abhishek Sur

                      Yes... RegisterStartupScript places the script after all the objects are rendered while RegisterClientScriptBlock places the JS at the beginning. Thus say you are calling a javascript using RegisterClientScriptBlock which gets an element, you will find this null, as the script gets executed just before any html is rendered. In case of RegisterStartupScript the script is placed after the html is generated. So If you want to place a javascript call in your html, always use RegisterStartupScript. Hope you got it. If not I can give you examples. :)

                      Abhishek Sur


                      My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

                      **Don't forget to click "Good Answer" if you like to.

                      M Offline
                      M Offline
                      Md Marufuzzaman
                      wrote on last edited by
                      #15

                      Thanks for your excellent explanation..:)

                      I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.


                      Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. Thanks Md. Marufuzzaman

                      A 1 Reply Last reply
                      0
                      • M Md Marufuzzaman

                        Thanks for your excellent explanation..:)

                        I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.


                        Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. Thanks Md. Marufuzzaman

                        A Offline
                        A Offline
                        Abhishek Sur
                        wrote on last edited by
                        #16

                        you are most welcome ... budd :cool:

                        Abhishek Sur


                        My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

                        **Don't forget to click "Good Answer" if you like to.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups