|
-
Sep 17th, 2008, 02:30 PM
#1
Thread Starter
Member
[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?
-
Sep 18th, 2008, 07:21 AM
#2
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);
-
Sep 24th, 2008, 08:41 AM
#3
Thread Starter
Member
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)
-
Sep 24th, 2008, 08:59 AM
#4
Re: [RESOLVED] Using AJAX / net2.0 / Cant setFocus on textbox
That renders out to the same thing
-
Sep 24th, 2008, 10:32 AM
#5
Thread Starter
Member
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 
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...
Last edited by Eclipsyo; Sep 24th, 2008 at 11:30 AM.
-
Sep 29th, 2008, 03:47 AM
#6
New Member
Re: Using AJAX / net2.0 / Cant setFocus on textbox
Thank u
it has helped me...
ScriptManager1.SetFocus(TextBox2)[/QUOTE]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|