views:

523

answers:

2

Help! I'm using the ASP.Net Login control on a Login page, but the Login button no longer appears to be working and the Authenticate event is not firing. On clicking Log In, the page just returns to the Login page.

web.config extract

<authorization>
 <deny users="?" />
  <allow users="*" />
</authorization>

<authentication mode="Forms">
  <forms loginUrl="Login.aspx" timeout="15" defaultUrl="Default.aspx" />
</authentication>

I have also set the path of my App_Themes folder to be accessible to anonymous users, so that images and stylesheets etc. appear OK.

The login control itself has its DestinationUrl property set to "Default.aspx" and validation is working, as if I omit either the Username or Password fields, I get validation errors appearing on the page.

Login control markup:

<asp:Login ID="Login1" runat="server" LoginButtonType="Image" 
  Width="557px" DestinationPageUrl="~/Default.aspx" 
  InstructionText="To login, please enter your username and password below."
  DisplayRememberMe="False" OnAuthenticate="Login1_Authenticate" LoginButtonImageUrl="~/App_Themes/RDCU/Images/submit.gif">
  <InstructionTextStyle Font-Names="Verdana" Font-Size="Small" ForeColor="#00A4E8" Height="40px" />
   <TitleTextStyle CssClass="header" HorizontalAlign="Left" />
   <TextBoxStyle Width="200px" />
   <LabelStyle Font-Bold="True" />
</asp:Login>

It has worked previously, but I don't believe I've changed anything to make it stop working.

A: 

This may be a problem with your validation.

Assuming you have ASP.Net validation controls on the page, they can interfere with the validation that already exists for the login control. Try setting the ValidationGroup property of your validation controls to be the name of the Login control. This will place them in the same validation group as the login control, thus keeping the validation unified.

Something like this:

<asp:Login runat="server" ID="myLogin" DisplayRememberMe="false" 
     FailureText="Invalid user name or password" 
     UserNameLabelText="User Name:" TitleText=""
     LoginButtonText="Submit" TextBoxStyle-Width="175px">
</asp:Login>
<asp:CustomValidator runat="server" ID="cvTandC"
     ClientValidationFunction="validateTandC" Display="Dynamic"
     EnableClientScript="true" ErrorMessage="Please check to continue." 
     ForeColor="Red" ValidateEmptyText="true" 
     ValidationGroup="myLogin"></asp:CustomValidator>

Note the validation group on the last line.

Bob Mc
A: 

I managed to fix it myself by converting the Login control to a template, changing some properties, then resetting it to its original layout.

I'm not sure why this would make a difference (perhaps it forced a re-compile or something) but it's working now.

Thanks to those who tried to help.

Jazza