Link to home
Start Free TrialLog in
Avatar of angelsofgrace2006
angelsofgrace2006Flag for Portugal

asked on

Inserting JavaScript in a C# ASP.NET file

Hi,

I need to add a little JavaScript function in a C# asp.net file (part of a website).

This file doesn't allow for the <head>, <body> or <html> elements. It gives me the error:
"Only content controls are allowed directly in a content page that contains Content controls".

Meanwhile, a nice chap here told me to put in the <head> scetion of the master page the following:
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>

and in the <body>:
<asp:ContentPlaceHolder id="body" runat="server">
</asp:ContentPlaceHolder>

So I did.

And in the .aspx file i put the following just for the sake of testing:

<asp:Content ID="head" ContentPlaceHolderID="head" runat="server">

<script type='text/javascript'>

 function check()

{

   var txtBox1 = document.getElementById('<%= Email.ClientID %>');
   alert(txtBox1.value);
}  

</script>

</asp:Content>

 

And in the markup of the Email field of the registration form, I've added onclick:

<asp:TextBox id="Email" runat="server" MaxLength="128" columns="40" onclick='check' />

The problem is that I always het the error:
"The name Email [the id name of the first email textbox] doesn't exist in the current context".

What am I missing here ? Where to put the JavaScript code ?

Anyway, if you want to see what I'm trying to do with the .aspx file (the new user registration form), please check http://www.absinto.org/form.html (start filling the login box).

Any help would be appreciated. I really need this very much.

Warm Regards,
Mário Gamito
ASKER CERTIFIED SOLUTION
Avatar of alexpercsi
alexpercsi
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial