I created a customed layout template in which contains a TextBox and Button.
The javascript looks like this:
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!
Code:
<layouttemplate>
<asp:TextBox id="TxtUser" runat="server" />
<asp:Button id="myButton" runat="server" OnClientClick="myJavascriptFunction" />
</layouttemplate>
Code:
<script type=text/javascript>
function myJavascriptFunction ( )
{
var myVar = document.getElementById("<%= TxtUser.ClientID%>").value ;
...code goes on
}
</script>
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!