Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

Posted

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

Posted
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?
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...