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. Single TextBox on a Form

Single TextBox on a Form

Scheduled Pinned Locked Moved ASP.NET
helpcsharpdotnetsysadminquestion
14 Posts 5 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.
  • P Paul Riley

    Simplest possible example:

    <%@ Page language="c#" Codebehind="SingleTextBox.aspx.cs" AutoEventWireup="false" Inherits="MyTestWeb.SingleTextBox" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    	<HEAD>
    		<title>SingleTextBox</title>
    		<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
    		<meta name="CODE_LANGUAGE" Content="C#">
    		<meta name="vs_defaultClientScript" content="JavaScript">
    		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    	</HEAD>
    	<body>
    		<form id="SingleTextBox" method="post" runat="server">
    			<asp:Label id="myLabel" runat="server">Enter Something:</asp:Label><br>
    			<asp:TextBox id="myTextBox" runat="server"></asp:TextBox><br>
    			<asp:Button id="myButton" runat="server" Text="Submit"></asp:Button>
    		</form>
    	</body>
    </HTML>
    

    And the codebehind

    namespace MyTestWeb
    {
    	public class SingleTextBox : System.Web.UI.Page
    	{
    		protected System.Web.UI.WebControls.Label myLabel;
    		protected System.Web.UI.WebControls.TextBox myTextBox;
    		protected System.Web.UI.WebControls.Button myButton;
    	
    		private void Page_Load(object sender, System.EventArgs e)
    		{
    			if (IsPostBack)
    				myLabel.ForeColor = Color.Blue;
    			else
    				myLabel.ForeColor = Color.Red;
    		}
    
    		#region Web Form Designer generated code
    		override protected void OnInit(EventArgs e)
    		{
    			InitializeComponent();
    			base.OnInit(e);
    		}
    		
    		private void InitializeComponent()
    		{    
    			this.myButton.Click += new System.EventHandler(this.myButton_Click);
    			this.Load += new System.EventHandler(this.Page_Load);
    
    		}
    		#endregion
    
    		private void myButton_Click(object sender, System.EventArgs e)
    		{
    			Response.Redirect("MyRedirect.aspx");
    		}
    	}
    }
    

    Enjoy! :confused: Paul We all will feed the worms and trees
    So don't be shy
    - Queens of the Stone Age, Mosquito Song

    P Offline
    P Offline
    Paul Watson
    wrote on last edited by
    #4

    You are freaking me out here Paul! Just been fiddling with your problem and it is very strange. I can put a hundred buttons, drop downs, text areas, checkboxes, radio buttons and file inputs on the form, but if there is only one text box then the enter key does not fire the default buttons click event. As soon as I put in another text box (not a textmode=multiline either) it then works. So far I have not figured out the why nor does Google bring up anything. Very strange.

    Paul Watson
    Bluegrass
    Cape Town, South Africa

    Macbeth muttered: I am in blood / Stepped in so far, that should I wade no more, / Returning were as tedious as go o'er DavidW wrote: You are totally mad. Nice.

    P 1 Reply Last reply
    0
    • P Paul Watson

      You are freaking me out here Paul! Just been fiddling with your problem and it is very strange. I can put a hundred buttons, drop downs, text areas, checkboxes, radio buttons and file inputs on the form, but if there is only one text box then the enter key does not fire the default buttons click event. As soon as I put in another text box (not a textmode=multiline either) it then works. So far I have not figured out the why nor does Google bring up anything. Very strange.

      Paul Watson
      Bluegrass
      Cape Town, South Africa

      Macbeth muttered: I am in blood / Stepped in so far, that should I wade no more, / Returning were as tedious as go o'er DavidW wrote: You are totally mad. Nice.

      P Offline
      P Offline
      Paul Riley
      wrote on last edited by
      #5

      Paul Watson wrote: You are freaking me out here Paul! Right! So now you see how I lost my Sunday evening :). I tried everything you have. I'm working on an article about validation controls and figured that I must have done something wrong with those to cause it (it also doesn't trigger client-side validation!). So I broke it down to the simple form I posted in this thread and then built it up to see exactly what it takes to make it work. Then I tried google because I figured it must be a bug and it would be reported everywhere - nothing. Slightly reassuring to hear that it's not something screwy with my computer, but at least then I'd have known what the problem was. X| Paul We all will feed the worms and trees
      So don't be shy
      - Queens of the Stone Age, Mosquito Song

      A 1 Reply Last reply
      0
      • P Paul Riley

        Paul Watson wrote: You are freaking me out here Paul! Right! So now you see how I lost my Sunday evening :). I tried everything you have. I'm working on an article about validation controls and figured that I must have done something wrong with those to cause it (it also doesn't trigger client-side validation!). So I broke it down to the simple form I posted in this thread and then built it up to see exactly what it takes to make it work. Then I tried google because I figured it must be a bug and it would be reported everywhere - nothing. Slightly reassuring to hear that it's not something screwy with my computer, but at least then I'd have known what the problem was. X| Paul We all will feed the worms and trees
        So don't be shy
        - Queens of the Stone Age, Mosquito Song

        A Offline
        A Offline
        Andy Smith
        wrote on last edited by
        #6

        this is "normal" browser behavior. With only a single textbox and a button, you'll notice that the browser doesn't send the button's key/value pair in the form post data. This is a legacy thing that MS did to emulate netscape way back when they were playing catch-up with NS 3.0 or something. because there is no key-value pair in the form post, there's no way for the framework to know which control caused the post back, and therefore no click events are fired. To get around this issue, I suggest you use my free DefaultButtons[^] control.

        P 1 Reply Last reply
        0
        • P Paul Riley

          Here's a strange problem: If I have a web form with just a label, a textbox and a submit button and hit "Enter" in the textbox, it posts back to the server but doesn't perform the MyButton_Click event. If I drop another textbox onto the same form and hit "Enter" in either one of them, it posts back and performs the MyButton_Click event. Can anyone else replicate this problem? The page source doesn't look any different (apart, obviously, from the new textbox), so I have to wonder if this is a .NET Framework bug. But maybe not, maybe it's IE6 SP1 or even something ridiculously simple that I'm doing wrong. Does anyone know anything about this? Paul We all will feed the worms and trees
          So don't be shy
          - Queens of the Stone Age, Mosquito Song

          M Offline
          M Offline
          Masaaki Onishi
          wrote on last edited by
          #7

          Hello, the CPians around the world.;) One possiblity is that this happens the ASP Button texted "Submit". Did you try to change the letter rather than Submit? I guess that the button texted Submit is more closely related to HTML post or get method in the web browser, so this acts as HTML button? That is, ASP button just code <INPUT...> in html format in the client browser, so the web server just considers this is Submit html button. Then, ASP button behavior never happens?:confused: -Masaaki Onishi (eCoolSoft)- ASP.NET Web and Windows Application Development by C# and MFC. eCoolWebPanelBar(BETA) is availabe now. http://www.ecoolsoft.com

          P 1 Reply Last reply
          0
          • A Andy Smith

            this is "normal" browser behavior. With only a single textbox and a button, you'll notice that the browser doesn't send the button's key/value pair in the form post data. This is a legacy thing that MS did to emulate netscape way back when they were playing catch-up with NS 3.0 or something. because there is no key-value pair in the form post, there's no way for the framework to know which control caused the post back, and therefore no click events are fired. To get around this issue, I suggest you use my free DefaultButtons[^] control.

            P Offline
            P Offline
            Paul Riley
            wrote on last edited by
            #8

            Thanks for the info, Andy. I'll save the stream of curse words about what a stupid idea that is :-D. Andy Smith wrote: To get around this issue, I suggest you use my free DefaultButtons[^] control I don't really want to do that as it's for an article and I don't want to detract from the real issue. I might link to it as a possible workaround though. Paul We all will feed the worms and trees
            So don't be shy
            - Queens of the Stone Age, Mosquito Song

            1 Reply Last reply
            0
            • M Masaaki Onishi

              Hello, the CPians around the world.;) One possiblity is that this happens the ASP Button texted "Submit". Did you try to change the letter rather than Submit? I guess that the button texted Submit is more closely related to HTML post or get method in the web browser, so this acts as HTML button? That is, ASP button just code <INPUT...> in html format in the client browser, so the web server just considers this is Submit html button. Then, ASP button behavior never happens?:confused: -Masaaki Onishi (eCoolSoft)- ASP.NET Web and Windows Application Development by C# and MFC. eCoolWebPanelBar(BETA) is availabe now. http://www.ecoolsoft.com

              P Offline
              P Offline
              Paul Riley
              wrote on last edited by
              #9

              Masaaki Onishi wrote: One possiblity is that this happens the ASP Button texted "Submit". Interesting idea. Unfortunately, when I first noticed it, the text was still "Button" :) It seems Andy has the right idea. Very frustrating, but right. Paul We all will feed the worms and trees
              So don't be shy
              - Queens of the Stone Age, Mosquito Song

              1 Reply Last reply
              0
              • P Paul Riley

                Here's a strange problem: If I have a web form with just a label, a textbox and a submit button and hit "Enter" in the textbox, it posts back to the server but doesn't perform the MyButton_Click event. If I drop another textbox onto the same form and hit "Enter" in either one of them, it posts back and performs the MyButton_Click event. Can anyone else replicate this problem? The page source doesn't look any different (apart, obviously, from the new textbox), so I have to wonder if this is a .NET Framework bug. But maybe not, maybe it's IE6 SP1 or even something ridiculously simple that I'm doing wrong. Does anyone know anything about this? Paul We all will feed the worms and trees
                So don't be shy
                - Queens of the Stone Age, Mosquito Song

                L Offline
                L Offline
                leppie
                wrote on last edited by
                #10

                I get this when the Web Forms designer blatantly delete my events. Just check there. I have to check a page every time I work on it to make sure that half the stuff is not gone before I upload... I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02

                P 1 Reply Last reply
                0
                • L leppie

                  I get this when the Web Forms designer blatantly delete my events. Just check there. I have to check a page every time I work on it to make sure that half the stuff is not gone before I upload... I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02

                  P Offline
                  P Offline
                  Paul Riley
                  wrote on last edited by
                  #11

                  leppie wrote: I get this when the Web Forms designer blatantly delete my events Leppie, dude. It's not like you to answer without reading through the thread first, or at least trying it :) Seems this is actually a browser "feature". As for the designer deleting events, that never happens to me :touching wood:. The closest thing is if you delete the handler name from the properties and there's no code in the handler itself. Paul We all will feed the worms and trees
                  So don't be shy
                  - Queens of the Stone Age, Mosquito Song

                  L 2 Replies Last reply
                  0
                  • P Paul Riley

                    leppie wrote: I get this when the Web Forms designer blatantly delete my events Leppie, dude. It's not like you to answer without reading through the thread first, or at least trying it :) Seems this is actually a browser "feature". As for the designer deleting events, that never happens to me :touching wood:. The closest thing is if you delete the handler name from the properties and there's no code in the handler itself. Paul We all will feed the worms and trees
                    So don't be shy
                    - Queens of the Stone Age, Mosquito Song

                    L Offline
                    L Offline
                    leppie
                    wrote on last edited by
                    #12

                    Paul Riley wrote: Leppie, dude. It's not like you to answer without reading through the thread first, or at least trying it On the contrary, I usaully just write what I think before reading what others have written :) Bad habit! Just too many things on my mind (math exam on wed, why automake is screwing up my builds in linux, why VS.NET deletes all my code). :laugh: I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02

                    P 1 Reply Last reply
                    0
                    • P Paul Riley

                      leppie wrote: I get this when the Web Forms designer blatantly delete my events Leppie, dude. It's not like you to answer without reading through the thread first, or at least trying it :) Seems this is actually a browser "feature". As for the designer deleting events, that never happens to me :touching wood:. The closest thing is if you delete the handler name from the properties and there's no code in the handler itself. Paul We all will feed the worms and trees
                      So don't be shy
                      - Queens of the Stone Age, Mosquito Song

                      L Offline
                      L Offline
                      leppie
                      wrote on last edited by
                      #13

                      OK, I read the post completely and my findings are similar to Pauls. A single textbox just does a postback, quite annoying since what happens if the user clicked the button instead? I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02

                      1 Reply Last reply
                      0
                      • L leppie

                        Paul Riley wrote: Leppie, dude. It's not like you to answer without reading through the thread first, or at least trying it On the contrary, I usaully just write what I think before reading what others have written :) Bad habit! Just too many things on my mind (math exam on wed, why automake is screwing up my builds in linux, why VS.NET deletes all my code). :laugh: I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02

                        P Offline
                        P Offline
                        Paul Riley
                        wrote on last edited by
                        #14

                        leppie wrote: On the contrary, I usaully just write what I think before reading what others have written Really? You (usually) do a great job of covering it up. I used to do the same and I consistently made a fool of myself, so I'm trying to stop it now. :-D Paul We all will feed the worms and trees
                        So don't be shy
                        - Queens of the Stone Age, Mosquito Song

                        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