Monday, March 26, 2012

DropShadowExtender and SetFocus

Hi there,

I'm trying to set the focus to a textbox while using the DropShadowExtender, but it does not seem to work.

The code is something like this:

<asp:Panel id="panelContainer" runat="server">

<asp:Textbox id="txtName" runat="server" />

</asp:Panel>

<atlasToolkit:DropShadowExtenderID="dseLogin"runat="server"><atlasToolkit:DropShadowPropertiesTargetControlID="panelContainer"Width="5"Rounded="true"Opacity=".75"TrackPosition="true"ID="dsBehavior"/></atlasToolkit:DropShadowExtender>

And in the code behind:

protectedvoid Page_Load(object sender,EventArgs e)

{

this.SetFocus(this.txtName);

}

What am I doing wrong? Is this a bug? Is there a workaround?

Thanks,

Rudy

Try searching this forum group (groupid:34) for SetFocus, I seem to recall seeing a post about this emitting code that couldn't be read correctly by Atlas. Maybe? I'm taking a stab but try to find the existing posts.
I did search for similar problems with SetFocus, but the posts I found were related to the TextBoxWatermarkExtender, not the DropShadowExtender.

This problem happens (I think) because the ASP.NET call to WebForm_AutoFocus (inserted by Page.SetFocus) happens before Atlas load. When Atlas loads and DropShadow initializes, it needs to mess around with the DOM and I think the manipulations it does end up losing the focus. My recommendation is to set the focus with the following instead as Application.load fires only AFTER Atlas and related code is finished initializing:

<script type="text/javascript">
Sys.Application.load.add(function() { $("txtName").focus(); });
</script>

The complete sample follows:

<%@. Page Language="C#" %><%@. Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected override void OnLoad(EventArgs e) { base.OnLoad(e); }</script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <atlas:ScriptManager ID="ScriptManager1" runat="Server"> </atlas:ScriptManager> <asp:Panel ID="panelContainer" runat="server"> <asp:TextBox ID="txtName" runat="server" /> </asp:Panel> <atlasToolkit:DropShadowExtender ID="dseLogin" runat="server"> <atlasToolkit:DropShadowProperties TargetControlID="panelContainer" Width="5" Rounded="true" Opacity=".75" TrackPosition="true" ID="dsBehavior" /> </atlasToolkit:DropShadowExtender> </div> </form> <script type="text/javascript"> Sys.Application.load.add(function() { $("txtName").focus(); }); </script></body></html>

No comments:

Post a Comment