Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.NET With JavaScript

Status
Not open for further replies.

arpan

Programmer
Oct 16, 2002
336
IN
I have the following ASPX code:

<script language=&quot;JavaScript&quot;>
function showHide(){
if(document.scopeform.loc[0].checked==true){
document.scopeform.lname.style.visibility=&quot;hidden&quot;
}
else{
document.scopeform.lname.style.visibility=&quot;visible&quot;
}
}
</script>

<script language=&quot;VB&quot; runat=&quot;server&quot;>
Sub Page_Load(obj As Object,ea As EventArgs)
...................................
lname.DataSource=objDS.Tables(&quot;Locations&quot;).DefaultView
lname.DataBind()
End Sub

Sub SelectEName(obj As Object,ea As EventArgs)
.........................
.........................
End Sub
</script>

<form id=&quot;scopeform&quot; runat='server&quot;>
<asp:RadioButton id=&quot;allloc&quot; AutoPostBack=&quot;true&quot; GroupName=&quot;loc&quot; Text=&quot;All&quot; Value=&quot;allloc&quot; OnCheckedChanged=&quot;SelectEName&quot;
checked=&quot;true&quot; runat=&quot;server&quot;/>

<asp:RadioButton id=&quot;selloc&quot; GroupName=&quot;loc&quot; Text=&quot;Selected&quot; Value=&quot;selloc&quot; OnCheckedChanged=&quot;SelectEName&quot; onClick=&quot;showHide()&quot;
runat=&quot;server&quot;/>
</form>
<asp:ListBox id=&quot;lname&quot; DataTextField=&quot;LName&quot; DataValueField=&quot;LName&quot; runat=&quot;server&quot;>
</form>

Please note that in the above 2 radio buttons, the 1st radio button has AutoPostBack=&quot;true&quot; & 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=&quot;true&quot; 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=&quot;true&quot; 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
 
Arpan,

If your web browser is giving you an error message for the JavaScript, then the line number it is giving you is from the html page that is created by the server for the browser, not the .aspx code page. Do a &quot;view source&quot; to see the real location of the error.

Also, it's possible that you can fix your javascript by adding a semicolon at the end of these lines:
document.scopeform.lname.style.visibility=&quot;hidden&quot;
document.scopeform.lname.style.visibility=&quot;visible&quot;


HTH!

Kevin

Kevin B.
.Net Programmer [thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top