我想在 ASP.NET 中创建一个 ajax 服务器控件,在该应用程序中我有一个文本框,我想将该文本框的文本发送到在 ASP.NET ajax 服务器控件类中创建的函数,并且该函数返回一些基于文本。
我的应用程序使用从作为参考添加的外部 DLL 导入的服务器控件。此服务器控件将利用 AJAX 来完成其功能。
要使用我的控件,我将在 .aspx 页面上添加脚本管理器和我的控件,它应该会开始工作。
我想在 ASP.NET 中创建一个 ajax 服务器控件,在该应用程序中我有一个文本框,我想将该文本框的文本发送到在 ASP.NET ajax 服务器控件类中创建的函数,并且该函数返回一些基于文本。
我的应用程序使用从作为参考添加的外部 DLL 导入的服务器控件。此服务器控件将利用 AJAX 来完成其功能。
要使用我的控件,我将在 .aspx 页面上添加脚本管理器和我的控件,它应该会开始工作。
我的页面.aspx:
...
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/MyService.asmx" />
</Services>
</asp:ScriptManager>
...
<script>
MyNameSpace.MyService.MyMethod('some text', responseHandlerMethod, errorHandlerMethod);
</script>
...
我的服务.asmx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
namespace MyNameSpace
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class MyServiceClass: System.Web.Services.WebService
{
[ScriptMethod]
[WebMethod]
public string MyMethod(string SomeText)
{
return "Hi mom! " + SomeText;
}
}
}