Link to home
Start Free TrialLog in
Avatar of jyllan
jyllanFlag for Denmark

asked on

How do I copy text from one textbox to another textbox and in a Ajaxtoolkit tabpanel

Hi
I have a problem, I can't copy a textbox to another textbox in ajax toolkit tabcontainer/tabpanel
I get the error: TextboxAddNewCloseName2 is undefined, when I use
onchange="javascript:TextboxAddNewCloseName2.value = this.value;return true;"

And the error ducument.getElementByID[..] is null or not an object
when I use the code onchange="javascript:document.getElementById('<%= TextboxAddNewCloseName2.ClientID %>').value = this.value;return true"

See my full code sent by me


<%@ Page Language="C#"   AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="_Default2" %>
 
<%@ 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">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <cc1:TabContainer ID="TabContainer1" runat="server">
        <cc1:TabPanel runat="server" ID="tab1"><HeaderTemplate>tab1</HeaderTemplate><ContentTemplate>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate>
    <asp:Textbox ID="txtAddNewCreateName2" runat="server"    onchange="javascript:document.getElementById('<%= TextboxAddNewCloseName2.ClientID %>').value = this.value;return true" MaxLength="4" />  
                         <asp:Textbox ID="TextboxAddNewCloseName2" runat="server"  />  
         </ContentTemplate>
        </asp:UpdatePanel> 
        </ContentTemplate></cc1:TabPanel>
        </cc1:TabContainer>
          <asp:Textbox ID="Textbox1" runat="server"     onchange="javascript:document.getElementById('<%Textbox2.ClientID %>').value = this.value;return true" MaxLength="4" />  
                         <asp:Textbox ID="Textbox2" runat="server"  /> <br />              
      
    
    </div>
    </form>
</body>
</html>

Open in new window

Avatar of apresto
apresto
Flag of Italy image

You may have to use this method to get the Textbox because if you look at your HTML source code you will notice that the ID of the textbox is different.
document.getElementById("<%=TextboxAddNewCloseName2.ClientID%>").value
ASKER CERTIFIED SOLUTION
Avatar of sijishJohn
sijishJohn
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,
I guess you are reffering to a control inside an UpdatePanel from Outside the UpdatePanel. Extend your updatepanel refer below...
<%@ Page Language="C#"   AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="_Default2" %>
 
<%@ 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">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <cc1:TabContainer ID="TabContainer1" runat="server">
        <cc1:TabPanel runat="server" ID="tab1"><HeaderTemplate>tab1</HeaderTemplate><ContentTemplate>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate>
    <asp:Textbox ID="txtAddNewCreateName2" runat="server"    onchange="javascript:document.getElementById('<%= TextboxAddNewCloseName2.ClientID %>').value = this.value;return true" MaxLength="4" />  
                         <asp:Textbox ID="TextboxAddNewCloseName2" runat="server"  />  
      
        </ContentTemplate></cc1:TabPanel>
        </cc1:TabContainer>
          <asp:Textbox ID="Textbox1" runat="server"     onchange="javascript:document.getElementById('<%Textbox2.ClientID %>').value = this.value;return true" MaxLength="4" />  
                         <asp:Textbox ID="Textbox2" runat="server"  /> <br />              
      
        </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>

Open in new window