how to call a c# webmethod on mouseover of linkbutton in asp.net?

Total Post:104

Points:728
C# 
 1697  View(s)
Ratings:
Rate this:

Is it possible to call a c# webmethod on mouseover on Linkbutton ? what i want is to call a webmethod in which i am binding a repeater control with datatable. How? in aspx: 

<asp:LinkButton Text='<%#Eval("SNA")%>' ID="lnkpro1" runat="server" 
CssClass="linkbutton" servicemethod="GetRecords"
OnClick="btn_Click1" CommandArgument='<%# Eval("Sets") %>'></asp:LinkButton>

in aspx.cs: 

[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public void GetRecords(object sender, EventArgs e)
{
 
}

I am not getting the point that is how is it possible to call a webmethod on linkbutton mouseover. I have used a webmethod in textbox autocomplete extender but it has a propperty of calling a webmethod but is it so in this case also? Thank you.

  1. Post:194

    Points:1396
    Re: how to call a c# webmethod on mouseover of linkbutton in asp.net?

    Use ASP.NET AJAX Page Methods, like this: 

    [WebMethod]
    public static List<Record> GetRecords()
    {
        // Go to database to get list of records
        List<Record> listOfRecords = GetRecordsFromDatabase();
     
        return listOfRecords;
    }

    I made up the Record class here. A list of something needs to be returned, so I made it up for the example's sake.

    Now you can call the ASP.NET AJAX Page Method, like this: 

    $(document).ready(function() {
        $('.linkbutton').mouseover(function() {
            $.ajax({
                type:"POST",
                url:"PageName.aspx/GetRecords",
                data:"{}",
                contentType: "application/json; charset=utf-8",
                dataType:"json",
                success:function(result) {
                    // Dosomething with records returned here
                    // Useresult.d to get to JSON data
                }
            });
        });
    });

      Modified On Apr-07-2018 01:52:17 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!