?
Solved

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

Posted on 2011-10-03
10
Medium Priority
?
523 Views
Last Modified: 2012-05-12
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?!
0
Comment
Question by:ascendinternet
  • 6
  • 2
  • 2
10 Comments
 
LVL 7

Expert Comment

by:OklahomaDave
ID: 36902676
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
 
LVL 12

Expert Comment

by:rajapandian_81
ID: 36902685
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
 

Author Comment

by:ascendinternet
ID: 36902717
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 12

Expert Comment

by:rajapandian_81
ID: 36902745
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
 

Author Comment

by:ascendinternet
ID: 36902762
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
 
LVL 7

Expert Comment

by:OklahomaDave
ID: 36902792
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
 

Author Comment

by:ascendinternet
ID: 36902869
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
 

Author Comment

by:ascendinternet
ID: 36904100
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
 

Accepted Solution

by:
ascendinternet earned 0 total points
ID: 36908985
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
 

Author Closing Comment

by:ascendinternet
ID: 36938097
Turned out not to be a problem with asp.net but jQuery instead.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month16 days, 16 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question