Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Oct 20, 2009 01:27 PM by caroli
Jul 10, 2007 04:09 PM|LINK
Let me explain my scenario and the things that I have already tried:
I am on .Net 2.0 with latest verion of AJAX.
The page is based off of a master page. The textbox is inside an user control which is inside a TabPanel. The User Control is encapsulated with a AJAX UpdatePanel.
I have tried the following solution for setting focus to textbox etc
1. Page.From.DefaultFocus = TextBox.ClientID and it seems to be doing nothing. It does not give any error, but doe snot setfocus to the textbox. This has been added in the page-load event.
If I try the above code to setfocus to a default textbox, the application does nothing. No error, nothing. If you see the view source below below the clientid of the textbox is correct w.r.t. its control hierarchy.
ScriptManager.RegisterClientScriptBlock(Page, sender.GetType(), "FocusScr", "WebForm_AutoFocus('" + TBLastName.ClientID + "');", True)
This gives an error in indicating object required.
Any help or direction to tackle this issue will be appreciated.
Thanks in advance
Jul 10, 2007 10:32 PM|LINK
The reason you were getting those errors about the textbox's not being enabled was because they were not rendered yet. To fix this, put in a delay before setting focus.
Here is some code that works:
Hello other people
That should make your focus go to your textbox on page load and also when the tab is clicked.
Jul 11, 2007 01:02 PM|LINK
Thanks Pete, I will try your suggestion and post back my results.
Thanks for being so quick and so detail in your explanation
Jul 11, 2007 08:15 PM|LINK
Thanks Pete, your suggestion worked perfectly when the window was initially loaded. Your suggestion/idea was primarily responsible for my solving this problem.
But if I had a setfocus() requirement on subsiquent postbacks on that screen, it would not work. What I found was because I had updatepanel on this window which only performing partial postback the RegsiterStartupScript on subsequent calls would not get
registered, so in that case I had to revert using the ScripManager.RegisterStartupScript function.
This is what I ended up doing:
Because all our SetFocus() code on the server side is in our base class, and that is being used in lot of pages and user control, I had to make the fix to our base function.
Below is one such function for a TextBox control. I have this function overlaoded for other controls as well.
'If the current page did not have an ScriptManager included then use the Page.ClientScript.RegisterStartupScript else use 'ScriptManager.RegisterStartupScript
I added the
The call to function is
Jul 12, 2007 02:31 AM|LINK
Thats good example. [:)]
Thanks, it will help for me & others.
Jul 12, 2007 11:23 AM|LINK
Jul 16, 2007 04:11 PM|LINK
I tried your code above, after breaking it apart into:
Sep 16, 2008 09:47 AM|LINK
Q::setting the focus for first edit textbox ,of appropriate tabpanelwhich is in tab container which is in updatepanel
Re:write following script at the bottom of u r source
in page load write
private void panelone()
private void paneltwo()
Oct 20, 2009 01:27 PM|LINK
I have a page layout like this:
Any idea how to set the focus to a textbox in the formview?
Setfocus with MasterPage