none
how to submit a form when press enter?

    Question

  • hi,

    I have an aspx page where the first control is to select a radiobutton from a readiobuttonlist.

    when i press enter(which is a submit button): 

    i get a textbox. when i enter a value to textbox and press "Enter", it does not work .

    I have to click on submit Button with mouse.

     

    Wednesday, June 01, 2011 12:47 PM

All replies

  • did you create an event handler for button click?
    Mitja

    Wednesday, June 01, 2011 12:50 PM
  • Set the property UseSubmitBehavior = true on the button.

    Adam


    Ctrl+Z
    Wednesday, June 01, 2011 12:51 PM
  • i used UseSubmitBehavior = true on the second submit button. not working.

    CODE:

     <asp:radiobuttonlist id="radio_check" runat="server">

        <asp:listitem id="RadioButton_singlelead" runat="server"  Text="Create a Single Lead" value="0"/>

        <asp:listitem id="RadioButton_importfile" runat="server" Text="Import a File" Value="1"/>

      </asp:radiobuttonlist>

        <asp:RequiredFieldValidator ID="RequiredFieldValidator_radio_check" ControlToValidate="radio_check" runat="server" ErrorMessage="<span style='color:red'>Select an Option</span>"></asp:RequiredFieldValidator>

        <br />

         <asp:Button ID="Button_radio" runat="server" Text="Submit"  OnClick="onclick_checkradio"/>

        <asp:Panel ID="Panel_FileUpload" runat="server" Visible="false">

              Please Upload File: 

              <br /><br />

             <asp:FileUpload ID="FileUpload_excel" runat="server" />

             <br /><br />

          <%--  <asp:Button ID="Button_Submit" runat="server" Text="Continue" OnClick="onclick_Excel2Sql"/>--%>

        </asp:Panel>

       

        <asp:Panel ID="Panel_CheckMobile" runat="server" Visible="false">

        <p>Enter details:</p>

     <asp:Table ID="Table_Lead" runat="server">

        <asp:TableRow>

            <asp:TableCell Text="Mobile Number"  ></asp:TableCell>

            <asp:TableCell>

                <asp:TextBox ID="MobileCheck" runat="server" MaxLength="8"></asp:TextBox> 

                <asp:RequiredFieldValidator ID="RequiredFieldValidator_MobileCheck"  ControlToValidate="MobileCheck" ErrorMessage="Enter Mobile Phone" ValidationGroup="MobileVaidation" runat="server"  ></asp:RequiredFieldValidator>

                  <ajaxToolkit:FilteredTextBoxExtender  ID="FilteredTextBoxExtender_MobileCheck" TargetControlID="MobileCheck" FilterType="Numbers" runat="server" Enabled="True"></ajaxToolkit:FilteredTextBoxExtender>

            </asp:TableCell>

        </asp:TableRow> 

        <asp:TableRow>

            <asp:TableCell>

                <asp:Button runat="server" Text="Check Mobile" OnClick="check_Mobile" ValidationGroup="MobileVaidation" UseSubmitBehavior="true"/>

            </asp:TableCell>

         </asp:TableRow>

          <asp:TableRow>

         <asp:TableCell  ColumnSpan="4" >

             <asp:Literal ID="Literal_response" runat="server"></asp:Literal>

         </asp:TableCell>


          <asp:TableCell>

              <asp:HiddenField ID="HiddenField_accguid" runat="server" />

         </asp:TableCell>

        </asp:TableRow>

     </asp:Table>


        </asp:Panel>

    Wednesday, June 01, 2011 1:54 PM
  • That means that property is already set on another control. You'll have to check your other controls.

    Simply do a Ctrl+F on the asp.net script for "UseSubmitBehavior"

    Oh and for a textbox, you need AutoPostBack=True

    Adam


    Ctrl+Z
    Wednesday, June 01, 2011 2:16 PM
  • hi Adam,

     

    I added AutoPostBack=True for the textbox  <asp:TextBox ID="MobileCheck" runat="server" MaxLength="8"></asp:TextBox> 

    and also added UseSubmitBehavior="true" in     <asp:Button runat="server" Text="Check Mobile" OnClick="check_Mobile" ValidationGroup="MobileVaidation" UseSubmitBehavior="true"/>

    still when i press Enter the focus is to the first Submit button.

     

    Please help.

    Thursday, June 02, 2011 5:54 AM
  • Can you post the page directives?
    Ctrl+Z
    Thursday, June 02, 2011 10:17 AM
  • It should be this:

            <asp:Button ID="Button1" runat="server" Text="Button" 
                UseSubmitBehavior="False" />
            <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"></asp:TextBox>

    Ctrl+Z
    Thursday, June 02, 2011 10:25 AM
  • hi  Adam,

     

     

      <asp:Button ID="Button1" runat="server" Text="Button"  UseSubmitBehavior="False" />
            <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"></asp:TextBox>

     

    does not work.

     

    these are the Page directives.

     

    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"

        CodeBehind="Default.aspx.cs" Inherits="CrownPlazaApplication._Default" %>

     

    <%@ Register Assembly="System.Web.Ajax" Namespace="System.Web.UI" TagPrefix="ajaxToolkit" %>

    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

    here's the code:
    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
        CodeBehind="Default.aspx.cs" Inherits="CrownPlazaApplication._Default" %>
    <%@ Register Assembly="System.Web.Ajax" Namespace="System.Web.UI" TagPrefix="ajaxToolkit" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    </asp:Content>
    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
       <ajaxToolkit:AjaxScriptManager ID="AjaxScriptManager1" runat="server">
        </ajaxToolkit:AjaxScriptManager>
        <h2>
          CROWN PLAZA APPLICATION
        </h2>
       
       <asp:radiobuttonlist id="radio_check" runat="server">
        <asp:listitem id="RadioButton_singlelead" runat="server"  Text="Create a Single Lead" value="0"/>
        <asp:listitem id="RadioButton_importfile" runat="server" Text="Import a File" Value="1"/>
      </asp:radiobuttonlist>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator_radio_check" ControlToValidate="radio_check" runat="server" ErrorMessage="<span style='color:red'>Select an Option</span>"></asp:RequiredFieldValidator>
        <br />
         <asp:Button ID="Button_radio" runat="server" Text="Submit"  OnClick="onclick_checkradio"/>
            <%--<asp:Literal ID="Literal_Radio" runat="server"></asp:Literal>--%>
        <asp:Panel ID="Panel_FileUpload" runat="server" Visible="false">
              Please Upload File: 
              <br /><br />
             <asp:FileUpload ID="FileUpload_excel" runat="server" />
             <br /><br />
         <%--  <asp:Button ID="Button_Submit" runat="server" Text="Continue" OnClick="UploadBtn_Click"/>
         <asp:RegularExpressionValidator  id="FileUpLoadValidator" runat="server" ErrorMessage="<span style='color:red'>Upload XLS file only.</span>" 
            ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.xls|.XLS)$" ControlToValidate="FileUpload_excel">
        </asp:RegularExpressionValidator>--%>
            <asp:Literal ID="Literal_FileUpload" runat="server"></asp:Literal>
        </asp:Panel>
       
        <asp:Panel ID="Panel_CheckMobile" runat="server" Visible="false">
        <p>Enter details:</p>
     <asp:Table ID="Table_Lead" runat="server">
        <asp:TableRow>
            <asp:TableCell Text="Mobile Number"></asp:TableCell>
            <asp:TableCell>
                <asp:TextBox ID="MobileCheck" runat="server" MaxLength="8"  AutoPostBack="true"></asp:TextBox> 
                <asp:RequiredFieldValidator ID="RequiredFieldValidator_MobileCheck"  ControlToValidate="MobileCheck" ErrorMessage="Enter Mobile Phone" ValidationGroup="MobileVaidation" runat="server"  ></asp:RequiredFieldValidator>
                  <ajaxToolkit:FilteredTextBoxExtender  ID="FilteredTextBoxExtender_MobileCheck" TargetControlID="MobileCheck" FilterType="Numbers" runat="server" Enabled="True"></ajaxToolkit:FilteredTextBoxExtender>
            </asp:TableCell>
        </asp:TableRow> 
        <asp:TableRow>
            <asp:TableCell>
                <asp:Button runat="server" Text="Check Mobile" OnClick="check_Mobile" ValidationGroup="MobileVaidation" UseSubmitBehavior="false" />
            </asp:TableCell>
         </asp:TableRow>
          <asp:TableRow>
         <asp:TableCell  ColumnSpan="4" >
             <asp:Literal ID="Literal_response" runat="server"></asp:Literal>
         </asp:TableCell>
          <asp:TableCell>
              <asp:HiddenField ID="HiddenField_accguid" runat="server" />
         </asp:TableCell>
        </asp:TableRow>
     </asp:Table>
        </asp:Panel>
    </asp:content/>

     

    Thursday, June 02, 2011 11:23 AM
  • I dont' see a form tag with runat=server

    That might be the issue.

    Try wrapping a <form runat=server>your code here</form> around the body


    Ctrl+Z
    Thursday, June 02, 2011 11:50 AM
  • On can do this through javascript. Write folloeing script on onkeydown of Textbox control

    "Form1" is the name of the form and "SubmitButton" is the na,me of the submit button.

    "if ((event.which && event.which == 13) ||
        (event.keyCode && event.keyCode == 13))
        {document.Form1.SubmitButton.click();return false;}
        else return true;"

    Hope this helps.


    Thanks
    • Proposed as answer by Vishvvas Thursday, June 02, 2011 11:55 AM
    Thursday, June 02, 2011 11:55 AM
  • the form tag is in the master page
    Thursday, June 02, 2011 1:02 PM
  • as the form tag is used in master page 

    i cannot call another form tag inside the default.aspx page to call the javascript function.

     

    Thursday, June 02, 2011 1:03 PM
  • This should do it:

    <%@ Page Language="vb" AutoEventWireup="false" MasterPageFile="~/Site1.Master" CodeBehind="Default.aspx.vb" Inherits="WebApplication4._Default" %>
    
    <asp:content runat="server" ID="ContentPlaceHolder1" ContentPlaceHolderID="ContentPlaceHolder1" >
      <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" onenter="enter"></asp:TextBox>
    </asp:content>
    
    Partial Public Class _Default
      Inherits System.Web.UI.Page
    
      Protected Sub enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Page.IsPostBack Then
          Response.Write("PostBack")
        End If
      End Sub
    End Class
    
    Adam
    Ctrl+Z
    Thursday, June 02, 2011 4:50 PM
  • Pay attention to the handler: Handles Me.Load

    That's key.

    Adam


    Ctrl+Z
    Thursday, June 02, 2011 4:55 PM
  • For web application question, you need post them in the following forum:

    http://forums.asp.net

     


    Mike [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 06, 2011 9:51 AM