Java&.Net
两者之间。

隐藏文件代码:

using
System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        //注册当前类为 Ajax 类型

        AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default));

    }

    ///<summary>

    ///求和的方法

    ///</summary>

    ///<param name="t1">数字1</param>

    ///<param name="t2">数字2</param>

    ///<returns>返回,两数的和</returns>

    [AjaxPro.AjaxMethod]    //此方法为 Ajax 方法

    public int Count(int t1,int t2)

    {

        return t1 + t2;

    }

}



Aspx  文件代码


 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>无标题页</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <asp:TextBox ID="TextBox1" runat="server" Width="59px"></asp:TextBox>+

        <asp:TextBox ID="TextBox2" runat="server" Width="46px"></asp:TextBox>

        =<asp:TextBox ID="TextBox3" runat="server" Width="82px"></asp:TextBox>&nbsp;

        <input id="Submit1" type="button" value="计算" onclick="getadd();" /></div>

    </form>

    <script type="text/javascript">

    function getadd(){

        var a=parseInt(document.getElementById("TextBox1").value);

        var b=parseInt(document.getElementById("TextBox2").value);

        var c=_Default.Count(a,b).value; //调用在隐藏代码文件里的方法

        document.getElementById("TextBox3").value=c;

    }

    </script>

</body>

</html>



Web.Config 文件

 

<?xmlversion="1.0"?>

<configuration>

     <configSections>

         <sectionGroupname="ajaxNet">

              <!--

                   If you are using Microsoft .NET 1.1 please remove the two attributes

                   requirePermission and restartOnExternalChanges, they are only supported

                   with .NET 2.0.

              -->

              <sectionname="ajaxSettings"type="AjaxPro.AjaxSettingsSectionHandler,AjaxPro.2"requirePermission="false"restartOnExternalChanges="true"/>

         </sectionGroup>

     </configSections>

     <ajaxNet>

         <ajaxSettings>

              <urlNamespaceMappingsuseAssemblyQualifiedName="false"allowListOnly="false">

                   <!--

                       Set the attribute useAssemblyQualifiedName to true to enable

                       use of assemblies placed in the GAC by using the full assembly

                       qualified name.

                  

                       To hide internal knowledge of assemblies, classes and namespace

                       you can override the name of the virtual http endpoints.

                      

                       <add type="Namespace.Class1,Assembly" path="mypath" />

                   -->

              </urlNamespaceMappings>

              <jsonConvertersincludeTypeProperty="true">

                   <!--

                       This section can be used to add new IJavaScriptConverters to the

                       Ajax.NET Professional engine. If you want to disable built-in

                       converters you can use the remove tag.

             

                       <remove type="Namespace.Class1,Assembly"/>

                       <add type="Namespace.Class2,Assembly"/>

                      

                       <add type="AjaxPro.BitmapConverter,AjaxPro.2" mimeType="image/jpeg" quality="100"/>

                   -->

              </jsonConverters>

              <!--

                   Set the enabled attribute to true to get Stack, TargetSize and Source

                   information if an exception has been thrown.

              -->

              <debugenabled="false"/>

              <!--

                   This is the default configuration used with Ajax.NET Professional. You

                   can put there your static JavaScript files, or remove the path attribute

                   to completly disable the files.

             

                   <scriptReplacements>

                       <file name="prototype" path="~/ajaxpro/prototype.ashx" />

                       <file name="core" path="~/ajaxpro/core.ashx" />

                       <file name="converter" path="~/ajaxpro/converter.ashx" />

                   </scriptReplacements>

              -->

              <!-- <encryption cryptType="" keyType="" /> -->

              <!--

                   Set the enabled attribute to true to enable the use of an Ajax.NET Professional

                   token. This will send a token to the client that will be used to identify if the

                   requests comes from the same PC.

              -->

              <tokenenabled="false"sitePassword="password"/>

              <!--

                   The oldStyle section can be used to enable old styled JavaScript code or

                   functions that are not used any more.

             

                   <configuration>

                       <objectExtendPrototype/>

                       <appCodeQualifiedFullName/>

                       <allowNumberBooleanAsString/>

                       <sessionStateDefaultNone/>

                       <includeMsPrototype/>

                       <renderDateTimeAsString/>

                       <noUtcTime/>

                       <renderJsonCompliant/>

                       <useSimpleObjectNaming/>

                   </configuration>

              -->

         </ajaxSettings>

     </ajaxNet>

     <!-- Common ASP.NET configuration -->

     <appSettings/>

     <connectionStrings/>

     <system.web>

         <compilationdebug="true"/>

         <authenticationmode="Forms"/>

         <httpModules>

              <!--

              This HttpCompressionModule is only working for requests in "ajaxpro" folder. The module

              is available for ASP.NET 2.0.

              <add name="HttpCompressionModule" type="AjaxPro.HttpCompressionModule,AjaxPro.2"/>

              -->

         </httpModules>

     </system.web>

     <!-- Handler configuration for Ajax.NET Professional -->

     <locationpath="ajaxpro">

         <system.web>

              <httpHandlers>

                   <addverb="*"path="*.ashx"type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>

              </httpHandlers>

              <!--

                   If you need to have Ajax.NET Professional methods running on the

                   login page you may have to enable your own authorization configuration

                   here.

              -->

              <!--

              <authorization>

                   <deny users="?"/>

              </authorization>

              -->

         </system.web>

     </location>

     <!--

     If you are using the AjaxPro.BitmapConverter you have to use following location

     configuration to get a JPEG of the Bitmap.

     -->

     <!--

     <location path="ajaximage">

         <system.web>

              <httpHandlers>

                   <add verb="*" path="*.ashx" type="AjaxPro.AjaxBitmapHttpHandler,AjaxPro.2"/>

              </httpHandlers>

         </system.web>

     </location>

     -->

</configuration>

posted on 2007-12-25 13:07 Java&.Net 阅读(283) 评论(0)  编辑  收藏 所属分类: Asp.Net

只有注册用户登录后才能发表评论。


网站导航: