WebRequestManager对象的使用

WebRequestManager可以喝WebRequest对象一起使用。

WebRequestManager对象的add_completedRequest方法,可以用来处理所有WebRequest对象的请求程序。

Time.aspx

<%@ Page Language="C#" %>

<script runat="server">
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        Response.Write(DateTime.Now.ToUniversalTime());
    }
</script>

GlobalCompleted.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Networking</title>
    <script type="text/javascript">
        function pageLoad() {
            Sys.Net.WebRequestManager.add_completedRequest(completedHandler);

            var webRequest = new Sys.Net.WebRequest();
            webRequest.set_url("Time.aspx");

            var webRequest2 = new Sys.Net.WebRequest();
            webRequest2.set_url(TimedSleep.aspx);

            Sys.Net.WebRequestManager.executeRequest(webRequest2);
            Sys.Net.WebRequestManager.executeRequest(webRequest);
        }

        function completedHandler(executor) {
            if (executor.get_responseAvailable()) {
                $get(placeholder).innerHTML += "<br />" +
                    executor.get_webRequest().get_url() +
                    " returned " +
                    executor.get_responseData(); 
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <div id="placeholder">processing request</div>
    </div>
    </form>
</body>
</html>

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。