I have the following ASPX code:
<script language="JavaScript">
function showHide(){
if(document.scopeform.loc[0].checked==true){
document.scopeform.lname.style.visibility="hidden"
}
else{
document.scopeform.lname.style.visibility="visible"
}
}
</script>
<script language="VB" runat="server">
Sub Page_Load(obj As Object,ea As EventArgs)
...................................
lname.DataSource=objDS.Tables("Locations"
.DefaultView
lname.DataBind()
End Sub
Sub SelectEName(obj As Object,ea As EventArgs)
.........................
.........................
End Sub
</script>
<form id="scopeform" runat='server">
<asp:RadioButton id="allloc" AutoPostBack="true" GroupName="loc" Text="All" Value="allloc" OnCheckedChanged="SelectEName"
checked="true" runat="server"/>
<asp:RadioButton id="selloc" GroupName="loc" Text="Selected" Value="selloc" OnCheckedChanged="SelectEName" onClick="showHide()"
runat="server"/>
</form>
<asp:ListBox id="lname" DataTextField="LName" DataValueField="LName" runat="server">
</form>
Please note that in the above 2 radio buttons, the 1st radio button has AutoPostBack="true" & doesn't invoke any JavaScript function but the 2nd radio button invokes the JavaScript function showHide() in the onClick event but does not have the AutoPostBack property set to true.
Till this point, everything is fine. Now if I add the JavaScript onClick event in the 1st radio button (as I have done for the 2nd radio button) invoking the showHide() JavaScript function & keep AutoPostBack="true" as it is, then when the page loads, I am shown a JavaScript error, that too, which points at the lname.DataBind() line!!! Why is this happening? Why is the JavaScript error pointing to the VB.NET code? Next if I remove the AutoPostBack="true" from the 1st radio button but keep the onClick event
function, then I am not shown any such error. What's going wrong?
Thanks,
Arpan
<script language="JavaScript">
function showHide(){
if(document.scopeform.loc[0].checked==true){
document.scopeform.lname.style.visibility="hidden"
}
else{
document.scopeform.lname.style.visibility="visible"
}
}
</script>
<script language="VB" runat="server">
Sub Page_Load(obj As Object,ea As EventArgs)
...................................
lname.DataSource=objDS.Tables("Locations"
lname.DataBind()
End Sub
Sub SelectEName(obj As Object,ea As EventArgs)
.........................
.........................
End Sub
</script>
<form id="scopeform" runat='server">
<asp:RadioButton id="allloc" AutoPostBack="true" GroupName="loc" Text="All" Value="allloc" OnCheckedChanged="SelectEName"
checked="true" runat="server"/>
<asp:RadioButton id="selloc" GroupName="loc" Text="Selected" Value="selloc" OnCheckedChanged="SelectEName" onClick="showHide()"
runat="server"/>
</form>
<asp:ListBox id="lname" DataTextField="LName" DataValueField="LName" runat="server">
</form>
Please note that in the above 2 radio buttons, the 1st radio button has AutoPostBack="true" & doesn't invoke any JavaScript function but the 2nd radio button invokes the JavaScript function showHide() in the onClick event but does not have the AutoPostBack property set to true.
Till this point, everything is fine. Now if I add the JavaScript onClick event in the 1st radio button (as I have done for the 2nd radio button) invoking the showHide() JavaScript function & keep AutoPostBack="true" as it is, then when the page loads, I am shown a JavaScript error, that too, which points at the lname.DataBind() line!!! Why is this happening? Why is the JavaScript error pointing to the VB.NET code? Next if I remove the AutoPostBack="true" from the 1st radio button but keep the onClick event
function, then I am not shown any such error. What's going wrong?
Thanks,
Arpan