views:

21

answers:

0

hi, as you all know using [WebMethod] only accepts Static Methods, of course to avoid the whole Page life cycle, but sometimes you really need to access some other methods and properties of the page, and more you also know that [WebMethod] dont work with user controls.

now after reading on the New Dynamic Feature, i decided to do some experimentation to access other Properties.Methods and Controls methods on the page, and so far i was succesful in Getting the Page Properties and Methods. so i tried the following code

ASPX Code

<script type="text/javascript">
    $(document).ready(function () {
        // Add the page method call as an onclick handler for the div.
        $("#Button1").click(function () {
            $.ajax({
                type: "POST",
                url: "Default.aspx/MethodCall",
                data: data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    // Replace the div's content with the page method's return.
                    $("#Result").text(msg.d);
                }
            });
        });
    });
</script>

ASPX.CS Code

   [WebMethod]
public static string MethodCall()
{



    dynamic Current = HttpContext.Current.CurrentHandler;
    var Date= Current.GetDate();


    return Date;
}

public string GetDate()
{



    return DateTime.Now.ToString();
}

but i am concerned about the following if anyone can help please

-Does this way run the whole Page life Cycle ? -what is the best way to apply this to Usercontrol ?

thanks alot in advanced

related questions