Wednesday, March 21, 2012

Default Focus with the Login control and the Ajax RoundedCornersExtender

I have a problem that either has a simple solution or is an Ajax bug - I don't know which.

I've implemented the Login control inside a panel that has its corners enhanced by the RoundedCornersExtender. It looks great but one negative side effect is that the initial focus is no longer in the UserName textbox. Remove the extender and the problem goes away.

Any ideas?

Robert W.
Vancouver, BC

Hi Robert,

Can you show me a small, self-sufficient repro regarding this issue?


Raymond,

Greetings from the North end of the I-5 !!! :-)

One perfect example of this can be found here: http://pocketpollster.com/beta/Login/login.aspx

I looked for your e-mail address on here but can't find it. You can e-mail me here: A1 at PocketPollster dot Com

And then I can send you the source files back.

Robert



Robert, I think it will be better if you post a simple demo here. All the community may benefit from this. :)

I had a rough idea for solving your problem. Can you add a javascript function which will run on pageLoad? And set focus to the userName textbox in this method. For instance:

function pageLoad()

{

window.setTimeout(setfocus, 1000);

}

function setfocus()

{

$get("the client id ").focus();

}


Raymond,

I will try your workaround but hopefully you can let the Ajax guys at MS know of this definite bug. Here's the barebones of the code:

<%@. Page Language="C#" MasterPageFile="~/main.master" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="_login" %>
<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Panel ID="panelLogin" runat="server" Height="250px" Width="270px" BackColor="#F9F9F9">
<asp:Login ID="Login1" runat="server" BorderPadding="12">
<TitleTextStyle HorizontalAlign="Left" VerticalAlign="Top" Height="40px" Font-Bold="true" Font-Size="Large" />
<TextBoxStyle Width="140px" />
<LoginButtonStyle Width="70px" />
</asp:Login>
</asp:Panel>
<cc1:RoundedCornersExtender ID="RoundedCornersExtender1" runat="server" TargetControlID="panelLogin" BorderColor="black" Radius="5" />
</asp:Content>

protected void Page_Load(object sender, EventArgs e)
{
// Make the Sign In button the default button and place the cursor in the User Name textbox
if (!IsPostBack)
{
Page.Form.DefaultButton = Login1.FindControl("LoginButton").UniqueID; // This works!
Page.Form.DefaultFocus = Login1.FindControl("UserName").UniqueID; // Doesn't currently work because of the Ajax RoundedCornersExtender control
}
}

------------
- End of Code -

Robert


http://www.codeplex.com/AtlasControlToolkit/WorkItem/View.aspx?WorkItemId=11520


Gracias, amigo!!

Well, my app takes this one step further. While this is related to the Ajax RoundedCornersExtender, it is also aggravated by the Ajax TextBoxWatermarkExtender control as well. Basically, I have a MasterPage with a LoginView control on it, and my content page (Register.aspx) is a 2-step CreateUserWizard process. I managed to figure out how to handle the Default Button work around (LoginView login button was being defaulted), but then I came across the Focus issue. Due to the fact that I have the TBWE control on the textboxes I want to focus, the Ajax controls are overriding my focus settings. Using Raymond's workaround, I managed to be able to get Step 1 of my CreateUserWizard control to set the focus to my first textbox (though only 90% of the time). The problem is that I then don't have any recourse on setting the focus of the first control on the second step since the load event is already set. Any ideas?


Shouldn't this now be fixed with the latest release - 10920? If so, I still have the problem.


I've been on holidays so wasn't aware that it was released ... and on my birthday no less! The notes with the release do seem to indicate that the problem has been resolved.

Robert


I have downloaded the latest release and I still get this issue. Without the RoundedCornersExtender I can set the focus in a textbox on page load, as soon as I put one on the page the focus doesn't work. Anyone else still having this issue or is something not right in my set up?


I have now had the opportunity to test it too. It definitely is NOT fixed. I even went so far as to set the default focus to the actual (hard-coded) UserName control name but it did not work. With the RoundedCornerExtender it does, so I'm convinced that the bug is not fixed.

No comments:

Post a Comment