Link to home
Create AccountLog in
Avatar of LISCNY
LISCNY

asked on

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

Avatar of gamarrojgq
gamarrojgq

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.
ASKER CERTIFIED SOLUTION
Avatar of LISCNY
LISCNY

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of LISCNY

ASKER

This fixed the problem was I experiencing.