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
  1. Home
  2. Web Development
  3. ASP.NET
  4. Executing Textbox Text

Executing Textbox Text

Scheduled Pinned Locked Moved ASP.NET
10 Posts 3 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.
  • W Offline
    W Offline
    waheed awan
    wrote on last edited by
    #1

    i want to execute the text written in text box e.g i have a function public void func(string s) { } what i want to achieve is if i write func("waheed") in the textbox this function should be called on clicking a button i cant use if/case etc my requirement is this the textbox text will be passed to another function where this text will execute as code Thanks

    V N 2 Replies Last reply
    0
    • W waheed awan

      i want to execute the text written in text box e.g i have a function public void func(string s) { } what i want to achieve is if i write func("waheed") in the textbox this function should be called on clicking a button i cant use if/case etc my requirement is this the textbox text will be passed to another function where this text will execute as code Thanks

      V Offline
      V Offline
      Venkatesh Mookkan
      wrote on last edited by
      #2

      waheed awan wrote:

      i want to execute the text written in text box e.g i have a function public void func(string s) { } what i want to achieve is if i write func("waheed") in the textbox this function should be called on clicking a button

      If you want this on javascript try the below on the onclick event of the button, (OnClientClick, if it is a Server Side button)

      func(document.getElementById('MY_TEXTBOX').value)
      

      If you want the above in ASP.NET, double click button, it will take you to the code behind, where you can try the below code in the Button Click event,

      func(MY_TEXTBOX.Text);
      

      Here MY_TEXTBOX is the ID of the textbox you mentioned

      [Venkatesh Mookkan] My: Website | Yahoo Group | Blog Spot

      modified on Tuesday, February 12, 2008 9:52 PM

      N 1 Reply Last reply
      0
      • V Venkatesh Mookkan

        waheed awan wrote:

        i want to execute the text written in text box e.g i have a function public void func(string s) { } what i want to achieve is if i write func("waheed") in the textbox this function should be called on clicking a button

        If you want this on javascript try the below on the onclick event of the button, (OnClientClick, if it is a Server Side button)

        func(document.getElementById('MY_TEXTBOX').value)
        

        If you want the above in ASP.NET, double click button, it will take you to the code behind, where you can try the below code in the Button Click event,

        func(MY_TEXTBOX.Text);
        

        Here MY_TEXTBOX is the ID of the textbox you mentioned

        [Venkatesh Mookkan] My: Website | Yahoo Group | Blog Spot

        modified on Tuesday, February 12, 2008 9:52 PM

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #3

        document.getElementById returns an object. How will this work in your example?


        only two letters away from being an asset

        V 1 Reply Last reply
        0
        • W waheed awan

          i want to execute the text written in text box e.g i have a function public void func(string s) { } what i want to achieve is if i write func("waheed") in the textbox this function should be called on clicking a button i cant use if/case etc my requirement is this the textbox text will be passed to another function where this text will execute as code Thanks

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          First, it isn't a very smart idea to try executing arbitrary code entered from a textbox. If you want to do this on the client-side you need to use the eval function. http://www.w3schools.com/jsref/jsref_eval.asp[^] On the server-side you can try using CodeDOM http://msdn2.microsoft.com/en-us/library/y2k85ax6.aspx[^] However, it is VERY, VERY dangerous to try compiling code input from a textbox. Don't even think about it, try something else.


          only two letters away from being an asset

          W 2 Replies Last reply
          0
          • N Not Active

            document.getElementById returns an object. How will this work in your example?


            only two letters away from being an asset

            V Offline
            V Offline
            Venkatesh Mookkan
            wrote on last edited by
            #5

            It should be

            func(document.getElementById('MY_TEXTBOX').value);
            

            Thanks Marks for pointing out.

            [Venkatesh Mookkan] My: Website | Yahoo Group | Blog Spot

            1 Reply Last reply
            0
            • N Not Active

              First, it isn't a very smart idea to try executing arbitrary code entered from a textbox. If you want to do this on the client-side you need to use the eval function. http://www.w3schools.com/jsref/jsref_eval.asp[^] On the server-side you can try using CodeDOM http://msdn2.microsoft.com/en-us/library/y2k85ax6.aspx[^] However, it is VERY, VERY dangerous to try compiling code input from a textbox. Don't even think about it, try something else.


              only two letters away from being an asset

              W Offline
              W Offline
              waheed awan
              wrote on last edited by
              #6

              THANKS the arical you gave me reference is very helpful and it solved another problem that i was facing but here my problem is as i write func("vaue"); in the cs file the function is called what i want to achieve is when i write func("vaue"); in the textbox then on clicking the button the textbox should be executed

              N 1 Reply Last reply
              0
              • N Not Active

                First, it isn't a very smart idea to try executing arbitrary code entered from a textbox. If you want to do this on the client-side you need to use the eval function. http://www.w3schools.com/jsref/jsref_eval.asp[^] On the server-side you can try using CodeDOM http://msdn2.microsoft.com/en-us/library/y2k85ax6.aspx[^] However, it is VERY, VERY dangerous to try compiling code input from a textbox. Don't even think about it, try something else.


                only two letters away from being an asset

                W Offline
                W Offline
                waheed awan
                wrote on last edited by
                #7

                THANKS the arical you gave me reference is very helpful and it solved another problem of adding a class that i was facing but here my problem is as i write func("vaue"); in the cs file the function is called what i want to achieve is when i write func("vaue"); in the textbox then on clicking the button the textbox text should be executed

                1 Reply Last reply
                0
                • W waheed awan

                  THANKS the arical you gave me reference is very helpful and it solved another problem that i was facing but here my problem is as i write func("vaue"); in the cs file the function is called what i want to achieve is when i write func("vaue"); in the textbox then on clicking the button the textbox should be executed

                  N Offline
                  N Offline
                  Not Active
                  wrote on last edited by
                  #8

                  waheed awan wrote:

                  then on clicking the button the textbox should be executed

                  I don't understand what you are asking for here.:confused: Do you want something like; func("Console.WriteLine("Hello, World");" ) which causes "Hello, World" to be written to a console window?:confused:


                  only two letters away from being an asset

                  W 1 Reply Last reply
                  0
                  • N Not Active

                    waheed awan wrote:

                    then on clicking the button the textbox should be executed

                    I don't understand what you are asking for here.:confused: Do you want something like; func("Console.WriteLine("Hello, World");" ) which causes "Hello, World" to be written to a console window?:confused:


                    only two letters away from being an asset

                    W Offline
                    W Offline
                    waheed awan
                    wrote on last edited by
                    #9

                    i want to say the textbox will be used to write code statements and clicking the button will execute the statement written in the textbox Example; if in the textbox i write MessageBox.Show("Hello"); then clicking the button executes the statement in the textbox in this case display a messagebox

                    N 1 Reply Last reply
                    0
                    • W waheed awan

                      i want to say the textbox will be used to write code statements and clicking the button will execute the statement written in the textbox Example; if in the textbox i write MessageBox.Show("Hello"); then clicking the button executes the statement in the textbox in this case display a messagebox

                      N Offline
                      N Offline
                      Not Active
                      wrote on last edited by
                      #10

                      Then read my previous response about CodeDOM, and the warning that this is VERY dangerous thing, don't do it, think of another way.


                      only two letters away from being an asset

                      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