[ASP.NET2.0] How to invoke a javascript inside layouttemplate

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mattmao
    New Member
    • Aug 2007
    • 121

    [ASP.NET2.0] How to invoke a javascript inside layouttemplate

    I created a customed layout template in which contains a TextBox and Button.
    Code:
    <layouttemplate>
        <asp:TextBox id="TxtUser" runat="server" />
        <asp:Button id="myButton" runat="server" OnClientClick="myJavascriptFunction" />
    </layouttemplate>
    The javascript looks like this:
    Code:
    <script type=text/javascript>
    function myJavascriptFunction ( )
    {
    var myVar = document.getElementById("<%= TxtUser.ClientID%>").value ;
    
    ...code goes on
    }
    </script>
    But no matter where I put my javascript file, this script would always generate an error : Cannot find reference "TxtUser" in context.

    My code works fine if I remove the layouttemplate, it just seems that the "TxtUser" id is "hidden" by the layouttemplate.

    Can anyone help me? Thanks in advance!
Working...