TextBox, Enter key stroke

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lenniekuah
    New Member
    • Oct 2006
    • 126

    #1

    TextBox, Enter key stroke

    Hi Good Guys,
    I need your help. Please Help me and share your knowledge of sample coding with me.

    The WEBFORM1.ASPX is working well and I am very Puzzle by the data entry TEXTBOX. Each time after the User has input the data and hit ENTER KEY, very strangely all the TEXTBOX contained data have been cleared off data.

    How do I ensure that when ENTER KEY is pressed by user it will not removed all the TEXTBOX Data.

    Here is the sample coding of the data entry TEXTBOX.:

    Code:
    <div class="LeftMargin">
        <table style="width:100%;"          
                
        <!-- ------CustomerID and Address ------ -->
         <tr>
             <td align=left class="style2">
                 <asp:Label ID="lblCustID" CssClass="labelText" runat="server" Width="160px"   Text="Customer ID: *"></asp:Label>
                 <asp:TextBox ID="txtCustID" CssClass="textbox" runat="server" ></asp:TextBox>
             </td>
                    &nbsp;
              <td>
                <asp:Label ID="lblCustAddr" CssClass="labelText" runat="server" Width="150px" Text="Address :  *"></asp:Label>
              <asp:TextBox ID="txtCustAddr" CssClass="textbox" Width="250px"  runat="server" ></asp:TextBox >
              </td>                       
         </tr>                    
                <!-- ------ Contact name and City ------ --> 
         <tr>
              <td align=left class="style3">
                  <asp:Label ID="lblContname" CssClass="labelText" runat="server" Width="160px"  Text="Contact Name :*"></asp:Label>
                  <asp:TextBox ID="txtContName" CssClass="textbox" Width="300px" runat="server" ></asp:TextBox>
              </td>
                    &nbsp;
              <td class="style1">
                   <asp:Label ID="lblCity" CssClass="labelText" runat="server" Width="150px" Text="City : *"></asp:Label>
                   <asp:TextBox ID="txtCity" CssClass="textbox" Width="250px" runat="server" ></asp:TextBox> 
             </td>                     
           /tr>
                        
            <!-- ------ Only PostCode ------ -->
         <tr>
              <td align=left class="style2">
                 <asp:Label ID="lblBlank1" CssClass="labelText" runat="server" Width="460px" Text=""  ></asp:Label>                            
              </td>
                    &nbsp;
              <td>
                   <asp:Label ID="lblPostCode" CssClass="labelText" runat="server"  Width="150px" Text="Post Code: * "></asp:Label>
                   <asp:TextBox ID="txtPostCode" CssClass="textbox" Width="250px" runat="server" ></asp:TextBox>
             </td>
       </tr>                     
                        
      </table>
     </div>

    Thank You.

    Have a Good Day.
    Cheers,
    Lennie
  • MrMancunian
    Recognized Expert Contributor
    • Jul 2008
    • 569

    #2
    Hi Lennie,

    First, read up on this article: Understanding ASP.NET View State. It explains a lot about ASP.NET page life cycles. You need to actively save data in your controls. You can do this by adding a parameter to a textbox: EnableViewState .

    Change
    Code:
    <asp:TextBox ID="txtCustID" CssClass="textbox" runat="server" ></asp:TextBox>
    to
    Code:
    <asp:TextBox ID="txtCustID" CssClass="textbox" runat="server" EnableViewState="True" ></asp:TextBox>
    Good luck!

    Steven

    Comment

    • lenniekuah
      New Member
      • Oct 2006
      • 126

      #3
      Hi MrMancunian

      I did change made changes as per your suggestion but it's not working.

      Here are the few sample coding of the changes I made and tested it out

      Code:
      <asp:TextBox ID="txtCity" CssClass="textbox" Width="250px" runat="server" EnableViewState="true"></asp:TextBox> 
      <asp:TextBox ID="txtPostCode" CssClass="textbox" Width="250px" runat="server" EnableViewState="true" ></asp:TextBox>
      <asp:TextBox ID="txtCountry" CssClass="textbox" Width="250px" runat="server" EnableViewState="true"   ></asp:TextBox>

      Comment

      • MrMancunian
        Recognized Expert Contributor
        • Jul 2008
        • 569

        #4
        Originally posted by lenniekuah
        Hi MrMancunian

        I did change made changes as per your suggestion but it's not working.

        Here are the few sample coding of the changes I made and tested it out

        Code:
        <asp:TextBox ID="txtCity" CssClass="textbox" Width="250px" runat="server" EnableViewState="true"></asp:TextBox> 
        <asp:TextBox ID="txtPostCode" CssClass="textbox" Width="250px" runat="server" EnableViewState="true" ></asp:TextBox>
        <asp:TextBox ID="txtCountry" CssClass="textbox" Width="250px" runat="server" EnableViewState="true"   ></asp:TextBox>
        Did you read the article I linked you to?

        Comment

        • lenniekuah
          New Member
          • Oct 2006
          • 126

          #5
          Yes, I did read the article at the URL Link that you provided. I do not understand it as I cannot find the article relating to the TEXTBOX ENTER Key press situation. If there are sample coding relating to it I will be easier to understand logically.
          Last edited by Frinavale; Aug 2 '10, 07:32 PM. Reason: Removed bold highlighting.

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Hi Lenniekuah :)

            When you hit the enter key on a page it does the "default action" which typically means that a submit button submits the page to the server.

            Since enabling viewstate didn't work for you then I suggest you take a look at your Page Load event to see if you are clearing the text boxes there...

            If not there, then check the button handling code to see if you are removing the text somewhere in that code.

            Edit: oh wait a second.....are you using UpdatePanels?

            -Frinny

            Comment

            • lenniekuah
              New Member
              • Oct 2006
              • 126

              #7
              Hi Frinavale.

              Thank you very much for your suggestion.

              While testing it I set the debugger Breakpoint and noticed that when I press ENTER KEY on a TEXTBOX, These are the sequent of events. It does a PAGE LOAD event then BtnGVFill_Click .

              This BtnGVFill_Click contain the function the clear the TextBox. List below are the coding of Page Load and BtnGVFill_Click event:


              Code:
              Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
                 'retrieve connection string from Web.config
                  connstr = ConfigurationManager.ConnectionStrings("DataConnstr").ConnectionString
                      
                      If IsPostBack Then
                          intPage = 1
                          strCustID = Session("custid")
                      End If
                  End Sub
              
                  Protected Sub BtnGVFill_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnGVFill.Click
              
                      Dim intTotalPageCnt As Integer = 0
                      GridView1.PageIndex = intPage - 1
                      FLoadGridView()
                     [B] FCleartextBox()[/B]
              
                      intTotalPageCnt = GridView1.PageCount
                      Me.lblPage.Text = "Page : " & CType(intPage, String) & " of " & CType(intTotalPageCnt, String)
              
                  End Sub
              ----------------------------------------------------------------
              Regarding UPDATEPANELS , where about it it ? this is something new to me


              I welcome your suggestion or sample coding to fix the problem. You are very awesome and wonderful in sharing information. I need your help.

              Thank you,

              Have a Good Day.
              Cheers,
              Lennie
              Last edited by lenniekuah; Aug 2 '10, 09:54 PM. Reason: Imcomplete explanation

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                Check out the MSDN Library regarding .NET related questions :)

                This library has documentation on all .NET controls, concepts etc. It's the resource that I constantly use whenever I'm working in .NET

                There are quite a few articles on the UpdatePanel there :)

                -Frinny

                Comment

                • lenniekuah
                  New Member
                  • Oct 2006
                  • 126

                  #9
                  Hi Awesome Frinavale,
                  Thank you very much for helping me. You are very wondeful and generous in sharing information with me.

                  My codings are now working on the Web Page.
                  This is a sample of my amended coding:

                  I added this AutoPostBack ="False"

                  Code:
                   
                    <asp:TextBox ID="txtCustAddr" CssClass="textbox" Width="250px"  runat="server"  EnableViewState="true" AutoPostBack="false" TabIndex="3"  >
                  </asp:TextBox
                  Last edited by lenniekuah; Aug 3 '10, 10:31 PM. Reason: typo error

                  Comment

                  Working...