I'm trying to make use of some javascript code in a WebUserControl but seem to be failing miserably...
In a standard web form I can have the following code:
<form id="form1" runat="server">
<script language="javascript" type="text/javascript">
function SomeFunction()
{
var element = document.getElementById('ddlValues');
var textelement = document.getElementById('txtTest');
if (element.value == '2')
{
textelement.style.visibility = 'hidden';
}
else
{
textelement.style.visibility = 'visible';
}
}
</script>
<aspropDownList ID="ddlValues" runat="server" onchange="SomeFunction();">
<asp:ListItem Text="Value 1" Value="1"></asp:ListItem>
<asp:ListItem Text="Value 2" Value="2"></asp:ListItem>
<asp:ListItem Text="Value 3" Value="3"></asp:ListItem>
<asp:ListItem Text="Value 4" Value="4"></asp:ListItem>
</aspropDownList>
<asp:TextBox ID="txtTest" runat="server" Text="Text Example"></asp:TextBox>
</form>
This all works fine.
However when I introduce similar code into a WebUserControl and use this in a standard web form I get javascript errors indicating that the objects are not found.
It appears that the 'getElementById' (or my usage of it) does not work within a WebUserControl.
Can anyone offer any advice?
Thanks in advance,
Steve
In a standard web form I can have the following code:
<form id="form1" runat="server">
<script language="javascript" type="text/javascript">
function SomeFunction()
{
var element = document.getElementById('ddlValues');
var textelement = document.getElementById('txtTest');
if (element.value == '2')
{
textelement.style.visibility = 'hidden';
}
else
{
textelement.style.visibility = 'visible';
}
}
</script>
<aspropDownList ID="ddlValues" runat="server" onchange="SomeFunction();">
<asp:ListItem Text="Value 1" Value="1"></asp:ListItem>
<asp:ListItem Text="Value 2" Value="2"></asp:ListItem>
<asp:ListItem Text="Value 3" Value="3"></asp:ListItem>
<asp:ListItem Text="Value 4" Value="4"></asp:ListItem>
</aspropDownList>
<asp:TextBox ID="txtTest" runat="server" Text="Text Example"></asp:TextBox>
</form>
This all works fine.
However when I introduce similar code into a WebUserControl and use this in a standard web form I get javascript errors indicating that the objects are not found.
It appears that the 'getElementById' (or my usage of it) does not work within a WebUserControl.
Can anyone offer any advice?
Thanks in advance,
Steve