Search code examples
jqueryhtmlanchorserver-side

how to get href value in Server side when click the anchor tag


I have a table that contain anchor tag in each row, when click the anchor link i get href value using jquery and bind the href value in hidden field, at the same time i want to pass the hidden field value in server side..!

how to pass the hidden field value when click the anchor tag is this possible..? or suggest some other way


Solution

  • get href value using jquery like

       $(document).ready(function () {
                        $('.info_link').click(function () {
                            var href = $(this).attr('href');
                            getHREFValue(href);
                        });
                    });
    

    then using Ajax to pass the href value to server side

                    function getHREFValue(data) {
                        $.ajax({
                            type: "POST",
                            dataType: "json",
                            contentType: "application/json; charset=utf-8",
                            data: "{'HrefValue':'" + data + "'}",
                            url: "./List.aspx/Insert",
                            success: function (Record) {
    
                                if (Record.d == true) {
                                    console.log("Success");
                                }
                                else {
                                    console.log("Failure");
                                }
                            },
                            error: function (error) {
                                console.log(error);
                            }
                        });
                    }