ASP.Net Master Page, User Controls, Form default buttons Issue

I have a website built using .Net master pages (C#), on every page there is a "search" User Control.

On general pages, this works fine - entering text in the search box and either clicking the Search button or pressing Enter submits the search request and shows results.

The problem is on the page with the asp:Login control - whatever happens, the validation for the login form fires. If I try doing a search it highlights the login form fields as being in error and does not activate the search function.

I have tried putting an asp:panel around both the search elements and login control in their respective User Controls, with the DefaultButton set to the correct (?) control - but it still does not work.

What am I missig here?!
ascendinternetAsked:
Who is Participating?
 
ascendinternetAuthor Commented:
OK, found the problem ... an include file was invoking the jQuery validation plugin which only works on the entire form that it targets.

The problem is now solved - what I expected to happen with panels and validation groups is now working correctly.
0
 
OklahomaDaveCommented:
Why not just disable the search control for the login page? Or perhaps merely set it's visible property to false?

You should be able to access the control programmatically from your content page via the Master.xxx reference syntax.



0
 
rajapandian_81Commented:
Hi,

To activate the search button when enter key is pressed from search textbox, use below code.

txtSearch.Attributes.Add("onkeydown", "if(event.keyCode == 13) { document.getElementById('" + btnSearch.UniqueID + "').click(); return false; }");

Open in new window

0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
ascendinternetAuthor Commented:
Unfortunately, hiding or otherwise disabling the search is not an option.

Sorry, I forgot to mention that clicking the Search button OR pressing enter while in the search input field causes the Login form to validate. Therefore, it's not a case of trying to activate the Search button specifically.

For some reason, the Login form fields are validated whatever ... I need them not to be validated if the Search button (or enter key pressed while in the search box) is clicked.
0
 
rajapandian_81Commented:
Try setting the "CausesValidation" property of search button to "false".

<asp:Button id="btnSearch" runat="server" Text="Search" CausesValidation="False" />

Open in new window

0
 
ascendinternetAuthor Commented:
Mainly out of desperation ... I curently have CausesValidation="false" on ALL controls - the search text box and button, as well as the UserName, Password and Submit buttons in the Login form (I am using a "LayoutTemplate"), but it STILL validates the login fields regardless.
0
 
OklahomaDaveCommented:
If you can't disable the fields, and you can't disable the control, then why would you NOT expect those controls to validate?

0
 
ascendinternetAuthor Commented:
OklahomaDave - I am trying to do the same as this website https://www.lucozade.com/login/ - entering a search term and pressing enter does not cause the login fields to be validated.

I have found that if I enter any character(s) in the username and password fields then enter a search term and press enter, it works fine...?
0
 
ascendinternetAuthor Commented:
I have found that it works OK if I remove the <LayoutTemplate> in the Login control.

In the page source, I noticed that the page <form> tag was missing the following when I used the LayoutTemplate:

 onsubmit="javascript:return WebForm_OnSubmit();"

I used Firebug to add it in manually and it worked!? What is going on / what am I missing?!
0
 
ascendinternetAuthor Commented:
Turned out not to be a problem with asp.net but jQuery instead.
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.

All Courses

From novice to tech pro — start learning today.