ASP.NET 2.0 - Enter Key - Default Submit Button

Rate It (5)

Last post 11-04-2009 2:36 AM by Babunareshnarra. 79 replies.

Sort Posts:

  • Re: ASP.NET 2.0 - Enter Key - Default Submit Button

    01-04-2008, 6:34 AM

    bachbouch:

    For those who are using the .Net 2.0 login control, I just thought about a hacky way to implement the scenario where users can hit the Enter key to fire the login button event, here is how it works:

    1- wrap your login control into a Panel and call it Panel1.

    2- inset a button on stage and call it dummyButton, set it's width and height  to 0, set it border to none and it is background anad foreground to white set it is text to empty string.( this is way, dummybutton will be invisible). If you are wondering why wouldn't I just set the visibility to false, well the answer is that it won't work.

    3- set the defaultbutton of Panel1 to dummyButton and set put this code the dummyButton your click handler

    bool crediteUser = Membership.ValidateUser(Login1.UserName, Login1.Password);

    if (crediteUser)

    {

    FormsAuthentication.RedirectFromLoginPage(Login1.UserName,false);

    }

     

    Hope this helps

     

     

     I think I have a even better solution for the Default Enter Key in Login Control. You don't need to write any code. Just follow the following steps:

    1.  Convert the Login control into a template by selecting the control and clicking the the arrow button on the top right corner and select "Convert to Template".
    2.  In your Login control template design view, add a Panel into the template and put everything in the Login control into the Panel.
    3.  When you convert your Login control to a template, the submit button in the Login control is now separated out. Select on the submit button to find out its name and fill the name into the DefaultButton property of the Panel inside the Login control template.

     Problem solved.

     


     

  • Re: ASP.NET 2.0 - Enter Key - Default Submit Button

    01-16-2008, 5:48 AM
    • Member
      2 point Member
    • parcol
    • Member since 01-16-2008, 10:42 AM
    • Posts 1

    coolbear_lq@hotmail.com:

     I think I have a even better solution for the Default Enter Key in Login Control. You don't need to write any code. Just follow the following steps:

    1.  Convert the Login control into a template by selecting the control and clicking the the arrow button on the top right corner and select "Convert to Template".
    2.  In your Login control template design view, add a Panel into the template and put everything in the Login control into the Panel.
    3.  When you convert your Login control to a template, the submit button in the Login control is now separated out. Select on the submit button to find out its name and fill the name into the DefaultButton property of the Panel inside the Login control template.

     Problem solved.

     

     

    This does the job with indead minimal coding.

    To set the focus to the username textbox I added the following code to the Page_Load:

    TextBox userName = (TextBox)Login1.FindControl("UserName");
    userName.Focus();

    This works for me. 

     

  • Re: ASP.NET 2.0 - Enter Key - Default Submit Button

    01-22-2008, 1:31 AM
    • Member
      2 point Member
    • India.net
    • Member since 01-22-2008, 5:09 AM
    • Posts 3

    hi everyone , I am also having the same problem and tried all the solutions but they r working only for single text box.if i set defaultbutton property of a form then it works for first text box only. also i have tried other solutions ,plz suggest some solution.Idea

  • Re: ASP.NET 2.0 - Enter Key - Default Submit Button

    01-22-2008, 2:47 AM
    • Member
      682 point Member
    • rmdw
    • Member since 03-14-2005, 11:03 PM
    • Vancouver, BC, Canada
    • Posts 891

    I don't understand what you're trying to say.  An example would help as a starting point.

    I invite you to visit this page: http://pocketpollster.com/beta/Feedback/infoRequest.aspx   It works properly for my needs.  How close is yours to it?

    Robert 

    Robert Werner
    Vancouver, BC
    Technical Blog
    Pocket Pollster
  • Re: ASP.NET 2.0 - Enter Key - Default Submit Button

    01-22-2008, 5:18 AM
    • Member
      736 point Member
    • zirmandli
    • Member since 05-22-2007, 5:45 AM
    • Ahmedabad, India
    • Posts 108

    Hi

    to make button to default button for the page, try this

    Page.Form.DefaultButton = btnSubmit.UniqueID;

     

    Click on 'Mark as Answer' if this post is helpful.

    -- Benazir Mandli
  • Re: ASP.NET 2.0 - Enter Key - Default Submit Button

    02-18-2008, 11:31 AM
    • Participant
      1,322 point Participant
    • ezhillmaran
    • Member since 02-15-2008, 11:09 AM
    • Chennai
    • Posts 277

    I to face this problem in program. but i'm using master page. when i open another webform and enter the hit button it executes the master page button , but it supposed to execute current webform button

    thnks n regards,
    Maran.


  • Re: ASP.NET 2.0 - Enter Key - Default Submit Button

    03-26-2008, 5:05 AM
    • Member
      42 point Member
    • gnuts4lunch
    • Member since 03-29-2005, 3:50 PM
    • Posts 99

    i had the same problem and tried the code you suggested...i got the error below;

    Error 1 The name 'Login1' does not exist in the current context C:\inetpub\wwwroot\wbsa\index.aspx.cs 18 35 http://localhost/wbsa/
     

     

     

  • Re: ASP.NET 2.0 - Enter Key - Default Submit Button

    03-26-2008, 7:09 AM
    • Member
      42 point Member
    • gnuts4lunch
    • Member since 03-29-2005, 3:50 PM
    • Posts 99

    Hi Parcol,

    Can you show me some code on your panel workaround?

    I tried your suggestions and it gave me some errors.

    Thanks

  • Re: ASP.NET 2.0 - Enter Key - Default Submit Button

    04-24-2008, 3:27 AM
    • Member
      217 point Member
    • zubinjoshi
    • Member since 02-23-2008, 7:37 AM
    • Delhi India
    • Posts 72

    how this can be solved in .net 1.1

    suppose there are two frame one for new login and another for existing login ........ with 2 textboxes and one button in each frame...

    when user mouse is in the perticular textbox the corresponding button should fire ,,, as that we have in .net 2.0 through defaultbutton in div

    how can be done in .net 1.1

     

     

     

    Mark it Answer if it helps you :)
  • Re: ASP.NET 2.0 - Enter Key - Default Submit Button

    04-24-2008, 3:38 AM
    • Participant
      1,322 point Participant
    • ezhillmaran
    • Member since 02-15-2008, 11:09 AM
    • Chennai
    • Posts 277

    Set default button as new login for frame1 and existing login for frame 2  

    thnks n regards,
    Maran.


  • Re: ASP.NET 2.0 - Enter Key - Default Submit Button

    04-24-2008, 6:17 AM
    • Contributor
      2,772 point Contributor
    • thirumaran007
    • Member since 03-14-2007, 5:39 AM
    • India
    • Posts 571

    Hi Friend,

    Just use access key property to do that

    With Friendly,
    Thirumaran

    Please remember to click "Mark as Answer" on this post if it helped you
  • Re: ASP.NET 2.0 - Enter Key - Default Submit Button

    04-28-2008, 8:02 AM
    • Participant
      1,637 point Participant
    • ShivaKarthik
    • Member since 04-15-2008, 1:11 PM
    • Hyderabad
    • Posts 268

    No Need Of this  much of stuff.Just u can do in the following way

     //the button which you want as default button define it in defaultbutton

    <form id="form1" runat="server" defaultbutton= "btn_Submit">

    Regards,
    B.ShivaKarthik
    Developer
    Hyderabad,India

    -------------------------------------------------
    Don't Forget to Mark as Answer for the post that helped you.
    -------------------------------------------------
  • Re: ASP.NET 2.0 - Enter Key - Default Submit Button

    05-13-2008, 8:03 AM
    • Member
      2 point Member
    • Zarna
    • Member since 05-13-2008, 11:52 AM
    • Posts 1

    Page.Form.DefaultButton = Me.FindControl("Button1").UniqueID

    it works successfully .

    Write it on Page_Load Event

  • Re: ASP.NET 2.0 - Enter Key - Default Submit Button

    05-14-2008, 9:41 AM
    • Member
      39 point Member
    • stapes
    • Member since 11-18-2006, 6:25 PM
    • Posts 55

     

    Method did not work for me. Completely ignored my default button and continued to process another button when enter is pressed.
  • Re: ASP.NET 2.0 - Enter Key - Default Submit Button

    05-14-2008, 12:23 PM
    • Member
      682 point Member
    • rmdw
    • Member since 03-14-2005, 11:03 PM
    • Vancouver, BC, Canada
    • Posts 891

    The ideas presented already are good ones.  Here's another, more extensive example that definitely works:

                <asp:Panel ID="newsletterPanel" CssClass="newsletter" runat="server">
                  <table style="background-color:#B9C8FF; border-style:none; width:100%">

                    <tr>
                      <td class="smallText" colspan="2">
                        Sign up for our newsletter:
                      </td>
                    </tr>
                    <tr>
                      <td class="smallText">Email:</td>
                      <td class="rightTextBox">
                        <asp:TextBox ID="textBoxSubscribeEmail" CssClass="smallTextBox" runat="server" ValidationGroup="Newsletter" />
                      </td>
                    </tr>
                    <tr>
                      <td class="smallText">Name:</td>
                      <td class="rightTextBox"><asp:TextBox ID="textBoxSubscribeName" CssClass="smallTextBox" runat="server" ValidationGroup="Newsletter" /></td>
                    </tr>
                    <tr>
                      <td align="right" colspan="2">
                        <asp:Button ID="buttonSubscribe" CssClass="smallTextButton" runat="server" Text="Subscribe" OnClick="buttonSubscribe_Click" ValidationGroup="Newsletter" />
                        <br />
                        <div class="smallText" style="text-align:left; padding-top:5px">
                          <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                                                      EnableClientScript="true"
                                                      ControlToValidate="textBoxSubscribeEmail"
                                                      ErrorMessage="Missing Email address<br />"
                                                      Display="Dynamic" SetFocusOnError="True"
                                                      ValidationGroup="Newsletter"
                          />
                          <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
                                                      EnableClientScript="true"
                                                      ControlToValidate="textBoxSubscribeName"
                                                      ErrorMessage="Missing Name"
                                                      Display="Dynamic" SetFocusOnError="True"
                                                      ValidationGroup="Newsletter"
                          />
                          <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
                                                          EnableClientScript="true"
                                                          ControlToValidate="textBoxSubscribeEmail"
                                                          ValidationExpression=".*@.*\..*"
                                                          ErrorMessage="Email address is not valid"
                                                          Display="Dynamic" SetFocusOnError="true"
                                                          ValidationGroup="Newsletter"
                          />
                        </div>
                      </td>
                    </tr>         
                  </table>
                </asp:Panel>
                <cc1:RoundedCornersExtender ID="RoundedCornersExtender1" runat="server" TargetControlID="newsletterPanel" Radius="6" BorderColor="185, 200, 255" Color="185, 200, 255" />
              </ContentTemplate>
            </asp:UpdatePanel>


      // Pressed when the user wants to subscribe to the PP newsletter
      protected void buttonSubscribe_Click(object sender, EventArgs e)
      {
        string retMsg = DBAccess.AddSubscriber(textBoxSubscribeEmail.Text, textBoxSubscribeName.Text);
        ShowMessage(retMsg);
        textBoxSubscribeEmail.Text = "";
        textBoxSubscribeName.Text = "";
      }


      protected void Page_Load(object sender, EventArgs e)
      {
        // Make the Newsletter Subscribe button the default button
        if (!IsPostBack)
        {
          Page.Form.DefaultButton = buttonSubscribe.UniqueID;
        }
      }

     

    Robert Werner
    Vancouver, BC
    Technical Blog
    Pocket Pollster
Page 4 of 6 (80 items) « First ... < Previous 2 3 4 5 6 Next >