Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 23rd, 2013, 07:58 AM
Authorized User
Points: 303, Level: 6
Points: 303, Level: 6 Points: 303, Level: 6 Points: 303, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
Default MouseOver by adding an attribute

Hello Everyone, i am trying to do a mouseOver event in my Default.aspx page where the image changes on a mouseOver. The code I have below trying to add an attribute which changes the imageButton picture does not work, when the page is requested it gets rendered fine but when i enter the imageButton control with my cursor the browser comes up "Web Page Error". When i dubug the debugger comes up with this "breaking on JScript run time error - Object expected".

Any help would be greatly appreciated.
Mark

Default.aspx
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    </head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ImageButton ID="ImageButton1" runat="server" Height="139px" 
            ImageUrl="~/Images/Picture2.jpg" Width="158px" />
        </div>
    </form>
</body>
</html>
Page Behind
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    ImageButton1.Attributes["onMouseOver"] = "javascript:swapImageIn('~/Images/Picture1.jpg');return true;";
    ImageButton1.Attributes["onMouseOut"] = "javascript:swapImageOut();return true;";
    }
}
Reply With Quote
  #2 (permalink)  
Old May 23rd, 2013, 05:45 PM
Authorized User
Points: 303, Level: 6
Points: 303, Level: 6 Points: 303, Level: 6 Points: 303, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
Default

I have also tried the below but it still won't work

Mark

Code:
ImageButton1.Attributes.Add("onMouseOver", "javascript:swapImageIn('~/Images/Picture2.jpg');return true;");
Reply With Quote
  #3 (permalink)  
Old May 24th, 2013, 03:12 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

You haven't defined the swapImage JavaScript function anywhere. Does your page include it somehow or does it have a reference to an external JavaScript file you didn't post?

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #4 (permalink)  
Old May 24th, 2013, 08:49 AM
Authorized User
Points: 303, Level: 6
Points: 303, Level: 6 Points: 303, Level: 6 Points: 303, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
Default

Hi Imar and thanks for your reply. No I have not defined the swapImage javascript nor is there an external reference.

Would it be something like

Quote:
<script type ="text/javascript" id = "swapImageIn">
{
this.src = "~/Images/Picture1.jpg"
}
</script>
Thanks Again
Mark

Last edited by markhh; May 24th, 2013 at 09:13 AM.. Reason: Updating
Reply With Quote
  #5 (permalink)  
Old May 24th, 2013, 10:38 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Nope, you need to define a real function using something like.

function swapImageIn()
{
// .... Code here
}

Did you copy this code from somewhere? If so, didn't they include the swapImageIn and Out functions?

You may want to Google a bit for this as there are lots of useful tutorials out there. For example:

http://www.htmlite.com/JS019.php

http://stackoverflow.com/questions/1...image-on-hover

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
markhh (May 27th, 2013)
  #6 (permalink)  
Old May 27th, 2013, 04:34 AM
Authorized User
Points: 303, Level: 6
Points: 303, Level: 6 Points: 303, Level: 6 Points: 303, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
Default

Hi Imar, yes I will check the suggested sites out,

Thanks again
Mark
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select nodes whose attribute matches another node's attribute? nikolai XSLT 5 April 18th, 2018 11:30 AM
MouseOver/Out Filespit ASP.NET 3.5 Basics 3 February 26th, 2011 09:24 AM
Mouseover in xslt rabs XSLT 3 March 16th, 2009 05:48 AM
oPacity Mouseover crmpicco Javascript How-To 3 July 1st, 2005 09:43 AM
Adding an Element with Attribute to XML file xergic Classic ASP XML 0 November 20th, 2004 08:26 AM



All times are GMT -4. The time now is 06:29 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.