Click here to Skip to main content
15,895,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Experts ..
I have created a web services ..which is fetching data from database ..Now I have to shoe data on mouse hover ..but I am not able to call the services on mouse hover
C#
[WebMethod]
       public DataSet GetData()
       {
       if(cn.State==ConnectionState.Closed)
          {
              cn.Open();
          }

       SqlDataAdapter da = new SqlDataAdapter("select  notes_note,c.cand_fname + ' ' + cand_lname as name, n.notes_createddate,c.cand_id_pk from tb_notes n,tb_candidate_go_beta c where n.notes_about_id=c.cand_id_pk ", cn);
       DataSet dt = new DataSet();
       da.Fill(dt);
       return dt;
       cn.Close();
       }

Now i have call this services on mouse hover ..How i can do this ...please help
Posted
Updated 17-Nov-13 17:59pm
v2

you can simply call you web service with the help of jquery. Here is the sample coe for you.

XML
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript">



    function abc()
    {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "Webmethod.aspx/BindDataToDropDown",
            data: "{}",
            dataType: "Json",
            success: function (data) {
                 //   this function is called when you web method executed sucessfully.
                //    write code for binding data returned from web method.


                })
            }
        });
    }
</script>


Just simply call the function "abc()" on mouse hover event of the control it will the call the web service.


<img onmouseover="abc()" border="0" src="smiley.gif" alt="Smiley" width="32" height="32">
 
Share this answer
 
Hi,

Add jQuery [^] on your page and using jQuery you can acheive this in this way:
JavaScript
$(document).ready(function () {
          $('#YourElementID').mouseover(function() {
              $.ajax({
                  type: "GET",
                  url: "YourPage.aspx/Method",
                  dataType: 'json',
                  success: function (msg) {
                      alert(msg.d);
                  },
                  error: function (e) {
                      alert("error: " + e);
                  }
              });
          });
      });


and your c# method should be static in this case.
 
Share this answer
 
v2
Comments
vivek_2984 18-Nov-13 0:25am    
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript"> $(document).ready(function () {
$('#pop-up').mouseover(function () {
$(function() {
var moveLeft = 0;
var moveDown = 0;

$('a#trigger').hover(function(e) {
$('div#pop-up').show();
//.css('top', e.pageY + moveDown)
//.css('left', e.pageX + moveLeft)
//.appendTo('body');
}, function() {
$('div#pop-up').hide();
});

$('a#trigger').mousemove(function(e) {
$("div#pop-up").css('top', e.pageY + moveDown).css('left', e.pageX + moveLeft);
});

$.ajax({
type: "GET",
url: "http://localhost:50417/WebService1.asmx",
dataType: 'json',
success: function (msg) {
alert(msg.d);
},
error: function (e) {
alert("error: " + e);
}
});
});
});
</script>





this is not working .. Please help
tanweer 18-Nov-13 6:34am    
post your error message or in which statment its giving error? Please provide some detail here so that we can help you.
jst simple use webservices
and rnd kro bhai yha kya h
 
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