Undesired Ajax calendar extender focus on postback

Hi guys,
I have a child page that inherits a master page. The child page contains a text box, that has a calendar extender, working fine when you click on textbox.  However, everytime there's a postback, page focuses on the calendar textbox control causing the calendar to popup on every postbacks.  

I have tried the following to remove the focus on this control:
1) Changed the tab index = 3 because it is the 3rd control on the page from the top.
2) Used .focus property on other controls on the pageload event. Ex: txtOther.focus()
2) Tried setting to focus to other controls on the pageload event programatically using the script attached with no luck.  Ex: SetFocus(txtOther)

Thank you for your help.

Private Overloads Sub SetFocus(ByVal control As Control)
            Dim sb As New StringBuilder()

            sb.Append(vbCr & vbLf & "<script language='JavaScript'>" & vbCr & vbLf)
            'sb.Append("<!--" & vbCr & vbLf)
            sb.Append("function SetFocus()" & vbCr & vbLf)
            sb.Append("{" & vbCr & vbLf)
            sb.Append(vbTab & "document.")

            Dim p As Control = control.Parent
            While Not (TypeOf p Is System.Web.UI.HtmlControls.HtmlForm)
                p = p.Parent
            End While

            sb.Append(p.ClientID)
            sb.Append("['")
            sb.Append(control.UniqueID)
            sb.Append("'].focus();" & vbCr & vbLf)

            sb.Append("}" & vbCr & vbLf)
            sb.Append("window.onload = SetFocus;" & vbCr & vbLf)
            sb.Append("</script>")

          
End Sub

Open in new window

Private Overloads Sub SetFocus(ByVal control As Control)
            Dim sb As New StringBuilder()

            sb.Append(vbCr & vbLf & "<script language='JavaScript'>" & vbCr & vbLf)
            'sb.Append("<!--" & vbCr & vbLf)
            sb.Append("function SetFocus()" & vbCr & vbLf)
            sb.Append("{" & vbCr & vbLf)
            sb.Append(vbTab & "document.")

            Dim p As Control = control.Parent
            While Not (TypeOf p Is System.Web.UI.HtmlControls.HtmlForm)
                p = p.Parent
            End While

            sb.Append(p.ClientID)
            sb.Append("['")
            sb.Append(control.UniqueID)
            sb.Append("'].focus();" & vbCr & vbLf)

            sb.Append("}" & vbCr & vbLf)
            sb.Append("window.onload = SetFocus;" & vbCr & vbLf)
            sb.Append("</script>")

          
End Sub

Open in new window

LISCNYAsked:
Who is Participating?

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

x
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.

gamarrojgqCommented:
Hi,

Can you post the code of your page once it is render? to see how the SetFocus javascript function is finally written in the page.
0
LISCNYAuthor Commented:
I fixed the source of the problem so I do not need the setFocus function for this issue anymore.  

Problem: What I did was I created a textbox and added a MaskedEditExtender on it and then added CalendarExtender.  

Solution: As you can see in the source code, I moved the CalendarExtender up and pushed the MaskedEditExtender below the CalendarExtender.  This worked for me.


<asp:TextBox ID="txtInvoiceDate" runat="server" Width="100px" 
                           BackColor="AliceBlue" TabIndex="2" Font-Names="Arial" Font-Size="Small"></asp:TextBox>
                       <asp:CalendarExtender ID="txtInvoiceDate_CalendarExtender" runat="server" 
                           Enabled="True" TargetControlID="txtInvoiceDate">
                       </asp:CalendarExtender>
                         <asp:MaskedEditExtender ID="txtInvoiceDate_MaskedEditExtender" runat="server" 
                           CultureAMPMPlaceholder="" CultureCurrencySymbolPlaceholder="" 
                           CultureDateFormat="" CultureDatePlaceholder="" CultureDecimalPlaceholder="" 
                           CultureThousandsPlaceholder="" CultureTimePlaceholder="" Enabled="True" 
                           Mask="99/99/9999" MaskType="Date" TargetControlID="txtInvoiceDate">
                       </asp:MaskedEditExtender>

Open in new window

0

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
LISCNYAuthor Commented:
This fixed the problem was I experiencing.
0
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
ASP.NET

From novice to tech pro — start learning today.