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.
DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script
type="text/javascript">
function MyDelay()
html>
Notice the call to MyDelay at the end of the <script> block to set focus on initial page load. Also, notice the hook up to MyDelay in the TabPanel's OnClientClick event:
Peter Lee
Participant
786 Points
133 Posts
Re: SetFocus to a Textbox on PageLoad with MasterPage, TabPanel, UpdatePanel not working, please ...
Jul 10, 2007 10:32 PM|LINK
Hi PMK,
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:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AJAXEnabledWebApplication1._Default" %><%
@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %><!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script type="text/javascript"> function MyDelay(){
setTimeout("FocusFunction()", 1000);}
function FocusFunction(){
document.getElementById("TabContainer1_TabPanel1_TextBox2").focus();}
MyDelay();
</script> <html xmlns="http://www.w3.org/1999/xhtml" ><
head runat="server"> <title>Untitled Page</title>
</head><
body style="background-color: transparent"> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div> </div> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <cc1:TabContainer ID="TabContainer1" runat="server" Height="81px" Width="201px" style="position: absolute; left: 100px; width: 400px; top: 150px; height: 200px;"> <cc1:TabPanel ID="TabPanel1" runat="server" HeaderText="hello 1" OnClientClick="MyDelay" > <ContentTemplate> <asp:TextBox runat="server" ID="TextBox1"></asp:TextBox><
br /> <asp:TextBox runat="server" ID="TextBox2"></asp:TextBox><
br />Hello other people
</ContentTemplate> </cc1:TabPanel>
<cc1:TabPanel ID="TabPanel2" runat="server" HeaderText="hello 2"> <ContentTemplate>Hello people
</ContentTemplate> </cc1:TabPanel> </cc1:TabContainer> </ContentTemplate> </asp:UpdatePanel> </form> </body></
html> Notice the call to MyDelay at the end of the <script> block to set focus on initial page load. Also, notice the hook up to MyDelay in the TabPanel's OnClientClick event:<cc1:TabPanel ID="TabPanel1" runat="server" HeaderText="hello 1" OnClientClick="MyDelay" >
That should make your focus go to your textbox on page load and also when the tab is clicked.
Pete