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. General Programming
  3. C#
  4. textbox and button

textbox and button

Scheduled Pinned Locked Moved C#
learningcsharpquestion
7 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.
  • M Offline
    M Offline
    Mazdak
    wrote on last edited by
    #1

    I know this is dumb question,but I am beginner in C# and do not have any book about it. I have a text box and a button,when user press this button I want to check if the text boxes are filled or not,and if the text is empty,change the text of button,I use this but it does not work:

    	private void Button1\_Click(object sender, System.EventArgs e)
    	{
    		if(TextBox1.Text==null)
    			Button1.Text="Hello";
    	}
    

    Mazy "So,so you think you can tell, Heaven from Hell, Blue skies from pain,... How I wish,how I wish you were here."
    Wish You Were Here-Pink Floyd-1975

    S A 2 Replies Last reply
    0
    • M Mazdak

      I know this is dumb question,but I am beginner in C# and do not have any book about it. I have a text box and a button,when user press this button I want to check if the text boxes are filled or not,and if the text is empty,change the text of button,I use this but it does not work:

      	private void Button1\_Click(object sender, System.EventArgs e)
      	{
      		if(TextBox1.Text==null)
      			Button1.Text="Hello";
      	}
      

      Mazy "So,so you think you can tell, Heaven from Hell, Blue skies from pain,... How I wish,how I wish you were here."
      Wish You Were Here-Pink Floyd-1975

      S Offline
      S Offline
      Schnemar
      wrote on last edited by
      #2

      try this one: private void Button1_Click(object sender, System.EventArgs e) { if(TextBox1.Text.Length == 0) Button1.Text = "Hello"; } or set the Enabled-Property of the Button to false at startup and override the TextChange Property of your TextBox maybe like this: private void TextBox1_TextChanged(object sender, System.EventArgs e) { if(this.TextBox1.Text.Length > 0) { this.Button1.Text = "Click me"; this.Button1.Enabled = true; } else { this.Button1.Text = "Hello"; this.Button1.Enabled = false; } } rgrds :)Martin

      M 2 Replies Last reply
      0
      • S Schnemar

        try this one: private void Button1_Click(object sender, System.EventArgs e) { if(TextBox1.Text.Length == 0) Button1.Text = "Hello"; } or set the Enabled-Property of the Button to false at startup and override the TextChange Property of your TextBox maybe like this: private void TextBox1_TextChanged(object sender, System.EventArgs e) { if(this.TextBox1.Text.Length > 0) { this.Button1.Text = "Click me"; this.Button1.Enabled = true; } else { this.Button1.Text = "Hello"; this.Button1.Enabled = false; } } rgrds :)Martin

        M Offline
        M Offline
        Mazdak
        wrote on last edited by
        #3

        Thanx,I check it now:) Mazy "So,so you think you can tell, Heaven from Hell, Blue skies from pain,... How I wish,how I wish you were here."
        Wish You Were Here-Pink Floyd-1975

        1 Reply Last reply
        0
        • S Schnemar

          try this one: private void Button1_Click(object sender, System.EventArgs e) { if(TextBox1.Text.Length == 0) Button1.Text = "Hello"; } or set the Enabled-Property of the Button to false at startup and override the TextChange Property of your TextBox maybe like this: private void TextBox1_TextChanged(object sender, System.EventArgs e) { if(this.TextBox1.Text.Length > 0) { this.Button1.Text = "Click me"; this.Button1.Enabled = true; } else { this.Button1.Text = "Hello"; this.Button1.Enabled = false; } } rgrds :)Martin

          M Offline
          M Offline
          Mazdak
          wrote on last edited by
          #4

          I think I made amistake about the place of my question,it's in a web form.My button does not enable when I add some text to text box??? Is there any difference between windows form and web application in this case? Mazy "So,so you think you can tell, Heaven from Hell, Blue skies from pain,... How I wish,how I wish you were here."
          Wish You Were Here-Pink Floyd-1975

          S 1 Reply Last reply
          0
          • M Mazdak

            I think I made amistake about the place of my question,it's in a web form.My button does not enable when I add some text to text box??? Is there any difference between windows form and web application in this case? Mazy "So,so you think you can tell, Heaven from Hell, Blue skies from pain,... How I wish,how I wish you were here."
            Wish You Were Here-Pink Floyd-1975

            S Offline
            S Offline
            Schnemar
            wrote on last edited by
            #5

            I'm sorry, but I can't help you in this case. On my new Computer is only Win XP Home Edition installed. The Home Edition has no IIS, and without IIS i can't create Web-App's. I planed to Upgrade to Prof. Edition but the 'Update' isn't cheap !! So I hope that you can get help from another !! Rgrds Martin X|

            1 Reply Last reply
            0
            • M Mazdak

              I know this is dumb question,but I am beginner in C# and do not have any book about it. I have a text box and a button,when user press this button I want to check if the text boxes are filled or not,and if the text is empty,change the text of button,I use this but it does not work:

              	private void Button1\_Click(object sender, System.EventArgs e)
              	{
              		if(TextBox1.Text==null)
              			Button1.Text="Hello";
              	}
              

              Mazy "So,so you think you can tell, Heaven from Hell, Blue skies from pain,... How I wish,how I wish you were here."
              Wish You Were Here-Pink Floyd-1975

              A Offline
              A Offline
              AndyG
              wrote on last edited by
              #6

              Assuming VS.NET wired up your event correctly try changing your code to this: if(TextBox1.Text == "") Button1.Text="Hello"; Andy Gaskell, MCSD MCDBA

              M 1 Reply Last reply
              0
              • A AndyG

                Assuming VS.NET wired up your event correctly try changing your code to this: if(TextBox1.Text == "") Button1.Text="Hello"; Andy Gaskell, MCSD MCDBA

                M Offline
                M Offline
                Mazdak
                wrote on last edited by
                #7

                Thanks,that works Mazy "So,so you think you can tell, Heaven from Hell, Blue skies from pain,... How I wish,how I wish you were here."
                Wish You Were Here-Pink Floyd-1975

                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