asp ajax 1.0中的scriptmanagerproxy

來源:互聯網
上載者:User

   在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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.