asp ajax 1.0中的scriptmanagerproxy

   在asp.net ajax 1.0中,由于scriptmanager只能有一个,因此当有模版页的时候,就必须用scriptmanagerproxy来做桥梁了,举例子如下
,有两个JS文件, jscript1完成加法,jscript2完成乘法
// JScript1 文件
//求和
function sum(m,n)
{
  alert(eval(m)+eval(n));
}

// JScript2 文件
//求积
function product(a,b)
{
  alert(eval(a)*eval(b));
}

父模版页
<head runat="server">
    <title>无标题页</title>
    <script type="text/javascript">
    function GetSum()
    {
       m=document.getElementById("Text1").value;
       n=document.getElementById("Text2").value;
       sum(m,n);
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        <Scripts >
        <asp:ScriptReference Path="JScript1.js" />
        </Scripts>
        </asp:ScriptManager>
        <table ><tr> <td> 第一个值:</td>
                <td ><input id="Text1" type="text" /></td>  </tr>
              <tr><td >  第二个值:</td>
              <td><input id="Text2" type="text" /></td> </tr>          
             <tr><td >   两个值的和是:</td>
              <td><input id="Button1"  type="button" value="和" style="width: 51px" onclick="GetSum()" /></td> </tr>
                </table>
       
        <br />
       
        <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
        </asp:contentplaceholder>

内容页
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Content.aspx.cs" Inherits="Content" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <script type="text/javascript">
    function GetProduct()
    {
       a=document.getElementById("txt1").value;
       b=document.getElementById("txt2").value;
       product(a,b);
    }
    </script>
    <asp:ScriptManagerProxy id="ScriptManagerProxy1" runat="server">
       <Scripts >
        <asp:ScriptReference Path="JScript2.js" />
        </Scripts>
    </asp:ScriptManagerProxy>
        <table >
            <tr>
                <td>
                    第一个值:</td>
                <td >
                    <input id="txt1" type="text" /></td>
            </tr>
            <tr>
                <td >
                    第二个值:</td>
                <td>
                    <input id="txt2" type="text" /></td>
            </tr>
            <tr>
                <td >
                    两个值的积是:</td>
                <td>
                    <input id="btn"  type="button" value="积" style="width: 51px" onclick="GetProduct()" /></td>
            </tr>
        </table>
</asp:Content>

你可能感兴趣的:(JavaScript,Ajax,.net,asp.net,asp)