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?!
Gordon SaxbySenior Web DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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 reference syntax.


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

Gordon SaxbySenior Web DeveloperAuthor 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.
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Try setting the "CausesValidation" property of search button to "false".

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

Open in new window

Gordon SaxbySenior Web DeveloperAuthor 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.
If you can't disable the fields, and you can't disable the control, then why would you NOT expect those controls to validate?

Gordon SaxbySenior Web DeveloperAuthor Commented:
OklahomaDave - I am trying to do the same as this website - 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...?
Gordon SaxbySenior Web DeveloperAuthor 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?!
Gordon SaxbySenior Web DeveloperAuthor 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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gordon SaxbySenior Web DeveloperAuthor Commented:
Turned out not to be a problem with but jQuery instead.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.