[RESOLVED] Using AJAX / net2.0 / Cant setFocus on textbox
Hey guys,
First my environment is using AJAX and .net 2.0 framework. I have a button that toggles between showing a dropdown or a textbox. Basically the button is clicked, if the dropdown is visible, hide it and show the textbox and vice versa...
My issue is neither one of these code options are working.
1) page.SetFocus(txtInsertTime) doesn't work.
2) System.Web.UI.ScriptManager.RegisterClientScriptBlock _
(Me.txtInsertTime, Me.GetType(), "FocusOnTimeTB", "document.form1['txtInsertTime'].focus();", True)
I think its something do to with the AJAX and that the control becomes
visible after the script .setfocus happens...
In code I do set Me.txtInsertTime.Visible = True before I call page.SetFocus(txtInsertTime). And, I'm using page.SetFocus() other places but the controls are visible all the time...
Anyone have a solution, another way?
Re: Using AJAX / net2.0 / Cant setFocus on textbox
If the control does become visible later in the page's client side life cycle, you could then use RegisterClientScriptBlock, but do a
window.onload = (your js code to set focus);
Re: Using AJAX / net2.0 / Cant setFocus on textbox
Didn't work, thanks for trying. I figured it out tho... and will share it with others whom are new to AJAX.
IF the control is in an UpdatePanel you must use the:
scriptmanager.setfocus() and not the page.setfocus()
ex. ScriptManager1.SetFocus(TextBox2)
Re: [RESOLVED] Using AJAX / net2.0 / Cant setFocus on textbox
That renders out to the same thing ;)
Re: [RESOLVED] Using AJAX / net2.0 / Cant setFocus on textbox
absolutely! just as i was debugging, I used js on the aspx to set focus on a different textbox, one thats not in a updatepanel and i actually saw the cursor set focus to that textbox, so i knew my js code was working properly. However thereafter as the new txtTime textbox became visible, the focus was removed!
so just a FYI - scriptmanager.setfocus is the way to actually set focus on a control inside a updatepanel :D
It very well could be the way my code is written, but no matter which way i did it... actual JS function on the aspx page, JS registerscriptblock, or page.setfocus, it wouldnt set focus. So, I'm assuming here that in end the scriptmanager must get the last say, as its rendered to the client...
Re: Using AJAX / net2.0 / Cant setFocus on textbox
Thank u
it has helped me...
ScriptManager1.SetFocus(TextBox2)[/QUOTE]