OnTheAnvil Posted October 11, 2004 Posted October 11, 2004 I'd like to execute some javascript code when the user changes the value of a drop down list on my web page but I keep getting an error. Any thoughts? Code on my page: <script language="javascript"> function ddlMedicalErrorType_OnSelectedIndexChanged() { alert("HELLO"); } </script> . . . <asp:dropdownlist id="ddlMedicalErrorType" style="Z-INDEX: 138; LEFT: 480px; POSITION: absolute; TOP: 256px" runat="server" Width="128px" OnSelectedIndexChanged="ddlMedicalErrorType_OnSelectedIndexChanged();"> The error that I get is: Compiler Error Message: BC30456: 'ddlMedicalErrorType_OnSelectedIndexChanged' is not a member of 'ASP.IncidentLog_aspx'. I'd appreciate anything I can get. Thanks, OnTheAnvil Quote
eramgarden Posted October 12, 2004 Posted October 12, 2004 I think ddlMedicalErrorType_OnSelectedIndexChanged should be in your code behind and from there, call the javascript. Quote
OnTheAnvil Posted October 12, 2004 Author Posted October 12, 2004 The code samples that I showed are all in the HTML portion of my page if thats what you mean by code behind. Could you clarify what you mean? Maybe give me an example. Thanks Quote
eramgarden Posted October 12, 2004 Posted October 12, 2004 are u using VB.net or C#? where do you put your code? all in HTML? if so, why?? why not take advantage of ASP.Net's code behind? Quote
OnTheAnvil Posted October 13, 2004 Author Posted October 13, 2004 I'm using VB .NET and I'm not familiar with the code behind concept. Could you describe what you mean by code behind? The only way I've ever added javascript is by directly editing the HTML code on the .aspx page. Thanks Quote
eramgarden Posted October 13, 2004 Posted October 13, 2004 I;d say you need to read up on asp.net.. there are 2 pages: xxx.aspx and xxx.aspx.vb xxx.aspx.vb holds the code behind..the code written in VB. xxx.aspx holds the HTML stuff. Quote
OnTheAnvil Posted October 13, 2004 Author Posted October 13, 2004 It looks like we've been talking about the same thing in different terms. So back to my original question. The OnSelectedIndexChange event calls the ddlMedicalErrorType_OnSelectedIndexChanged() javascript function in the code behind. But when it compiles I get the error message. Does that help clarify my question? Quote
eramgarden Posted October 13, 2004 Posted October 13, 2004 i dont think you're using code behind..can u post your code here? Quote
Jeff B Posted October 19, 2004 Posted October 19, 2004 On The Anvil, You need to add "javascript:" to the front of your function call to let the framework know that you are intending to call a javascript function. Otherwise, it assumes that you are calling a VB.net or C#.net function, depending on the language you are using. Like this: <asp:dropdownlist id="ddlMedicalErrorType" style="Z-INDEX: 138; LEFT: 480px; POSITION: absolute; TOP: 256px" runat="server" Width="128px" OnSelectedIndexChanged="javascript:ddlMedicalErrorType_OnSelectedIndexChanged();"> Heres a little bit on the "Code-Behind" concept (VB.net example): The "Code-Behind" concept seperates the design from the code. All the HTML elements and javascript are in the *.aspx page while the VB.net code is in the *.aspx.vb page. The *.aspx page will reside on the server as is, while the *.aspx.vb will be compiled into a *.dll file to be placed in the bin directory. Now the VB.net code may be written in the .aspx page instead between <script runat="server"> </script> tags. The code part will still be compiled into a *.dll file to be placed in the bin directory. Why use the "Code-Behind"? In many production environments there are separate teams that work on each part of the Web Application. The Design team generally uses WYSWYG tools like Microsoft FrontPage or Macromedia DreamWeaver to design their pages while the programming team works on the code for these pages. In previous technologies like ASP/JSP the code is mingled throughout the page along with the design, so if the design team modified the design, there was a big possibility that they overwrote some of the programming code too! This makes life difficult for both the design and programming teams and many times leads to locked horns between the two! In ASP.NET you can have two separate files, one for the design and another for the code. This is the most elegant solution, since the design team can work on the design page (with peace) and the programming team on their code without having to worry about clashes between the two. Understand that this is a vastly over simplified explanation of the "Code-Behind" concept. I hope this shed at least a little light on this subject. Jeff B Here is some more reading on the subject. http://www.developer.com/net/csharp/article.php/3087791 Quote
OnTheAnvil Posted October 19, 2004 Author Posted October 19, 2004 Thanks Jeff. Thats exactly what I needed to know. ~OnTheAnvil Quote
Jeff B Posted October 19, 2004 Posted October 19, 2004 Thanks Jeff. Thats exactly what I needed to know. ~OnTheAnvilAnytime. Just glad I could help. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.