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.
2.
Page.RegisterStartupScript("Startup", "<script language=JavaScript>document.getElementById(" & Chr(34) & Me.TBLastName.ClientID() & Chr(34) & ").focus();</Script>")
This one gives a javascript error indicating that the application is trying to setfocus to a control that is not enabled, but that is not true as the textbox is enabled and I can manually setfocus and type in it.
3.
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.
PMKAJAX
0 Points
4 Posts
SetFocus to a Textbox on PageLoad with MasterPage, TabPanel, UpdatePanel not working, please help...
Jul 10, 2007 04:09 PM|LINK
Hello Everyone,
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.
<script type="text/javascript">
<!--
WebForm_AutoFocus('ctl00_SampleContent_WUCCamperMenuOptionsAsTab2_TabStCamperOptions_TbCamperLkp_WUCCamperLookup2_WUCCamperInquiry1_TBLastName');
// -->
</script>
2.
Page.RegisterStartupScript("Startup", "<script language=JavaScript>document.getElementById(" & Chr(34) & Me.TBLastName.ClientID() & Chr(34) & ").focus();</Script>")
This one gives a javascript error indicating that the application is trying to setfocus to a control that is not enabled, but that is not true as the textbox is enabled and I can manually setfocus and type in it.
3.
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
PMK