I am facing a problem in using more than one instance of an aspx user control in a aspx page. This happens when I tried to fetch User control element value through Java script.
User Control Code:
<script type="text/javascript">
function ucFun()
{
var a = document.getElementById("<%=tbName.ClientID%>");
alert(a.value);
return false;
}
</script>
<asp:Label Text="Name" runat="server" ID="lblname"></asp:Label>
<asp:TextBox ID="tbName" runat="server" ></asp:TextBox>
<asp:Button ID="btSubmit" runat="server" Text="Go" OnClientClick="ucFun()" />
Web Form Code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc:cont runat="server" ID="ucID" />
<uc:cont runat="server" ID="Cont1" />
<uc:cont runat="server" ID="Cont2" />
</div>
</form>
</body>
</html>
on clicking the Go button, it displays null int he alert box, as the element is undefined. However, When I have one instance of User control in the form, it rightly displayed the text box value.
Is there any way we should write this..