• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

Change Focus for Submit Buttons When Users Presses Enter in AJAX .NET Forms

Hello,

I have an AJAX ASP.NET form that uses a masterpage and C# on the code-behind.

My problem is, that one of the first elements on the page is an ImageButton that is in the masterpage.  I have many different areas of the page that consist of one or two text boxes, that are associated (or intended to be associated) with a submit button.  When a user fills out the required information for any one of these areas (by filling out the one or two text boxes) and presses the enter key, the first ImageButton is fired, instead of the submit button that is associated with the one or two textboxes.  The user expects the submit button associated with the  one or two textboxes to be fired/clicked instead (since the user was working in that area of the page).

Is there anyway that I can ensure that when a user is working in one of these areas of the page (i.e. they've filled out a couple of these textboxes) that the associated (or intended) submit button's click event is fired?

Thank You!
0
suchandsuch
Asked:
suchandsuch
1 Solution
 
GuitarRichCommented:
according to this link you can wrap each collection of controls in an asp:panel and use the DefaultButton property  
http://stackoverflow.com/questions/865227/determine-at-runtime-which-submit-button-to-use

another tutorial on it

http://www.ehow.com/how_2021386_default-button-aspnet-c-vb.html


<asp:Panel runat="server" DefaultButton="btnEmployeeSeach">
    <label for="ctl00_cpMain_txtEmployeeSearch">Employee Name:</label><asp:TextBox id="txtEmployeeSearch" runat="server" CssClass="TextBox" />
    <asp:Button ID="btnEmployeeSeach" runat="server" Text="Search" onclick="btnEmployeeSeach_Click" CssClass="button" />
</asp:Panel>    
<asp:Panel runat="server" DefaultButton="btnCustomerSeach">
    <label for="ctl00_cpMain_txtCustomerSearch">Customer Name:</label><asp:TextBox id="txtCustomerSearch" runat="server" CssClass="TextBox" />
    <asp:Button ID="btnCustomerSeach" runat="server" Text="Search" onclick="btnCustomerSeach_Click" CssClass="button" />
</asp:Panel>

Open in new window

0
 
suchandsuchAuthor Commented:
Thank you GuitarRich, that was EXACTLY what I was hoping for.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now