5 Replies - 8635 Views - Last Post: 22 April 2012 - 10:04 PM Rate Topic: -----

#1 kiwwi229   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-April 12

Mouse Hover event-- on images( save Image ID in database)

Posted 15 April 2012 - 11:06 AM

Currently Im doing research on something that are related to graphical password.

Can I know is that possible ASP.net(vb) can do such things..:

when mouse hover over a image, that image id will automatically save in database?
Lets say that there are multiples images display in GridView. Only 2 images is the answer. So when user use mouse hover on those images, those images id that mouse hover will saved in database. Then, system will check 2 images id is in the list that mouse hover just now or not.

Really hope someone can try to help me up here. Thanks in advanced. :)

Is This A Good Question/Topic? 0
  • +

Replies To: Mouse Hover event-- on images( save Image ID in database)

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5315
  • View blog
  • Posts: 14,185
  • Joined: 18-April 07

Re: Mouse Hover event-- on images( save Image ID in database)

Posted 15 April 2012 - 11:45 AM

Sure. This can be accomplished with some Javascript which detects the mouse hovering over the image and then calls a function which will fetch the id of the image being hovered over, and through an AJAX call, you can send that ID to a script which will store the ID for you in the database.

Things you will need...

1) Look up onmouseover event in Javascript
2) Look at using the "this" keyword in the function that onmouseover will call
3) Look up how AJAX works (this is again just Javascript). You can also look into the jQuery plugin and use that for AJAX requests too if you like.
4) A page which will accept the IDs passed to it and insert them into the database for you.

:)
Was This Post Helpful? 0
  • +
  • -

#3 kiwwi229   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-April 12

Re: Mouse Hover event-- on images( save Image ID in database)

Posted 15 April 2012 - 08:24 PM

Thanks for the reply :)
It really help me up. At least I know it is possible to do that. I will try to follow your guide, study on those stuff.
Do let me know if you found some tutorial/website url that will help me up too :) Im willing to share my code here if it is success.;)
Thanks in advanced...
Was This Post Helpful? 0
  • +
  • -

#4 kiwwi229   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-April 12

Re: Mouse Hover event-- on images( save Image ID in database)

Posted 22 April 2012 - 10:38 AM

View PostMartyr2, on 15 April 2012 - 11:45 AM, said:

Sure. This can be accomplished with some Javascript which detects the mouse hovering over the image and then calls a function which will fetch the id of the image being hovered over, and through an AJAX call, you can send that ID to a script which will store the ID for you in the database.

Things you will need...

1) Look up onmouseover event in Javascript
2) Look at using the "this" keyword in the function that onmouseover will call
3) Look up how AJAX works (this is again just Javascript). You can also look into the jQuery plugin and use that for AJAX requests too if you like.
4) A page which will accept the IDs passed to it and insert them into the database for you.

:)


The guide is really helps me alot. Currently I can do "Hovering the image, image name will appear at the page." But now my main problem is... Everytime the page refresh, images will randomly appear. I randomize those images by using vb.net code behind. So, everytime the image's name is different. Jquery code that I search doesnt help me retrieve the image name/path that have been randomly appear in page. Most of the code are they set the image's name and retrieve by "scr". Any idea how to solve it?? :whatsthat:

This is what I get now....
<script type="text/javascript">
$(document).ready(function () {
//Image1 refer to <asp:Image ID="Image1" runat="server" > which is randomize by vb.net code behind.
$('#Image1').mouseover(function () {
var display = '/images/butt_go.gif'; <----- here is my problem. I should not set my own image'name because everytime it randomize, it should be different. ?? any idea??
//display_text_here= my div class name
$(".display_text_here").text(display); });
});
</script>


Thanks in advance :rolleyes:
Was This Post Helpful? 0
  • +
  • -

#5 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: Mouse Hover event-- on images( save Image ID in database)

Posted 22 April 2012 - 01:08 PM

where are you supposed to be getting your image names from?
Was This Post Helpful? 0
  • +
  • -

#6 kiwwi229   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-April 12

Re: Mouse Hover event-- on images( save Image ID in database)

Posted 22 April 2012 - 10:04 PM

View PostNakor, on 22 April 2012 - 01:08 PM, said:

where are you supposed to be getting your image names from?



web code
<asp:TableCell> <asp:Image ID="Image1" runat="server" />
</asp:TableCell>
.....Image2....3....

vb code behind
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

'Programmatically pick a random image from the ~/Images directory
Image1.ImageUrl = PickImageFromDirectory1("~/images/GP/")
.....2..
......3..
End Sub


Private Function PickImageFromDirectory1(ByVal directoryPath As String) As String
Dim dirInfo As New DirectoryInfo(Server.MapPath(directoryPath))
Dim fileList() As FileInfo = dirInfo.GetFiles()
Dim numberOfFiles As Integer = fileList.Length

'Pick a random image from the list
Dim rnd As New Random
Dim randomFileIndex As Integer = rnd.Next(0, 30)
Dim imageFileName As String = fileList(randomFileIndex).Name
Dim fullImageFileName As String = Path.Combine(directoryPath, imageFileName)
Return fullImageFileName
End Function


So actually random images that appear on web is based on vb.net code behind.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1