tags:

views:

34

answers:

1

I have the following jQuery event that gets fired every time an anchor is clicked. How can I pass a asp.net control (lets say a panel called "pnl_info") as one of the parameters, in addition to the "target" parameter i'm already passing?

<script type="text/javascript">
    $(document).ready(function() {
        $("a").click(function(event) {
            $.ajax({
                type: "POST",
                url: "Default.aspx/Click",
                data: "{target:'" + event.target + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                error: function(xhr, ajaxOptions, thrownError) {
                alert(xhr.responseText);
                    $("#myContent").html(xhr.statusText);

                    //alert(xhr.responseText);
                },
                success: function(msg) {
                    alert(msg.d);
                }
            });
            return false;
        })
    })
</script>
A: 

Could you do something like...

data: {target: event.target, info: $("#pnl_info").val()}
Jason
Would I be able to make changes to pnl_info itself if i passed it in this way? For example add a new control?
Abe Miessler
@Abe: no, this way you'll be passing some value to the server. if you want to make any changes on the client, return the necessary data and use it on the client, in the `success` method.
Alexander Gyoshev
@Abe, when you post using JQuery, you are not using the ASP.Net postback mechanism. You are basically bypassing the entire ASP.Net page lifecycle, so the web method that you are calling won't know anything about the controls (from an ASP.Net standpoint.)
camainc