How can i send the command Argument value of linkbutton on mouseover of link button to c# webmethod?

StackOverflow https://stackoverflow.com/questions/20416769

Question

I want to send the command Argument value of linkbutton on mouseover of it to the c# webmethod via Json. Is it possible? How? This how i am trying but it is not working: aspx code:

 <asp:LinkButton Text='<%#Eval("SNA")%>' ID="lnkpro1" runat="server" CssClass="linkbutton"
                                                        OnClick="btn_Click1" CommandArgument='<%# Eval("Code") %>' onmouseover="return get();" ToolTip='<%# Eval("code") %>'></asp:LinkButton>

json:

functionget(e) {
     var Code= e.title; 
        $.ajax({
            type: "POST",
            url: "Default.aspx/MyMethod",
            data: "{'Code':'" + code+ "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(result) {





            }
        });

    }

C# webmethod:

public static List<string>   Records(string code)
    {

        List<string> getrecords = new List<string>();

        return getrecords;
    }

web method is not hitting onmouseover of linkbutton if i write tooltip but it is the only way i am thinking by which i can send the command argument of link button to c# method. Thank you all.

Was it helpful?

Solution

replace you onmouseover="return get();" with following

onmouseover='<%# "return get(" + Eval("code") + ");" %>'

and in java script get function get code as argument like following

function get(strcode){

// pass this strcode in you ajax parameter 
$.ajax({
        type: "POST",
        url: "Default.aspx/MyMethod",
        data: "{'Code':'" + strcode + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(result) {





        }
    });
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top