Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Me Have the following code the html code work properly in htmlpage but the asp code not working in asp page.
///html code
<body>
<script>
function changeImage() {
element = document.getElementById('myimage');
if (element.src.match("loginm")) {
element.src = "images/login.jpg";
}
else {
element.src = "images/loginm.png";
}
}
</script>

<img id="myimage" önclick="changeImage()"
src="images/loginm.png" width="100" height="180">

Click the light bulb to turn on/off the light


</body>



///asp.net code
<head>
<script>
function changeImage() {
element = document.getElementById('myimage');
if (element.src.match("loginm")) {
element.src = "images/login.jpg";
}
else {
element.src = "images/loginm.png";
}
}

</script>
</head>
<body>
<asp:Image ID="myimage" runat="server" onclick="changeImage()" src="images/loginm.png" />
</body>
Posted
Comments
Murugesan22 11-Apr-14 2:35am    
Post on error
Murugesan22 11-Apr-14 2:36am    
try to add form in aspx page

1 solution

try this,

Add form with runat="server"

C#
<head>
<script>
function changeImage() {
element = document.getElementById('myimage');
if (element.src.match("loginm")) {
element.src = "images/login.jpg";
}
else {
element.src = "images/loginm.png";
}
}
 
</script>
</head>
<body>
 <form id="form1" runat="server">
<asp:image id="myimage" runat="server" onclick="changeImage()" src="images/loginm.png" xmlns:asp="#unknown" />

</body> </head>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900