Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
1.91/5 (3 votes)
See more:
Hi i need to get 5 valariables from javascript and save it in a C# Class.
How can i do that? please help me.
Posted
Comments
Raul Iloc 10-Jul-14 1:28am    
Did you try as I suggested in my solution?

1 solution

You can do this by using AJAX call.
1.In the next example I am doing indirectly AJAX call by using jQuery, and I am sending 5 parameters with values from the current page controls:
C#
function computeQuantity(computeUrl) {
    
    var itemComment1 = $("#itemComment").val();
    var itemAmount1 = $("#itemAmount").val();
    var itemLength1 = $("#itemLength").val();
    var itemWidth1 = $("#itemWidth").val();
    var itemThickness1 = $("#itemThickness").val();
    //
    $.post("/" + computeUrl + "/ComputeQuantity", { itemComment: itemComment1, itemAmount: itemAmount1, itemLength: itemLength1, itemWidth: itemWidth1, itemThickness: itemThickness1 },
        function (result) { $("#defineQuantity").html(result); });
    //
    return true;
}


JavaScript


2.In the next example I am using direct AJAX call for sending address parameter:
JavaScript
function CartAddressChanged() {
        var address = $("#_addressTypeDropDown").val();
        $.ajax({
            type: "POST",
            url: "/Order/CartForNewAddress",
            data: "address=" + address,
            success: function () {
                document.location = "/Order/ShoppingCart";
            },
            error: function (jqXHR, exception) {
                alert('Uncaught Error.\n' + jqXHR.responseText);
            }
        }); //end ajax call
        return false;
    };
 
Share this answer
 
v2

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