作者:Dflying Chen http://dflying.cnblogs.com/

PS:又是好久没更新了,惭愧啊……希望大家继续支持我。

在这个系列的上面几篇(开发ASP.NET Atlas服务器端Extender控件——基本概念以及预先需求开发ASP.NET Atlas服务器端Extender控件——编写客户端Behavior开发ASP.NET Atlas服务器端Extender控件——编写服务器端Extender & Dflying近期动向)中,我们完整地开发了一个Atlas服务器端Extender控件。本篇是其中的最后一篇,将介绍如何使用前面编写的这个控件。

首先,建立一个Atlas Web Site,并添加对上面编写的控件的引用,请参考下图:
开发ASP.NET Atlas服务器端Extender控件——在实际开发中使用编写好的控件

然后,编写用于检查用户名的Web Service,这里我仅仅简单的假定用户名不能取Dflying。当然在具体的实现中您可以从数据库中查询并验证。将其保存为UserRegisterService.asmx

开发ASP.NET Atlas服务器端Extender控件——在实际开发中使用编写好的控件[WebService(Namespace = "http://www.dflying.net/")]
开发ASP.NET Atlas服务器端Extender控件——在实际开发中使用编写好的控件[WebServiceBinding(ConformsTo 
= WsiProfiles.BasicProfile1_1)]
}

然后,在页面中添加AtlasScriptManager

开发ASP.NET Atlas服务器端Extender控件——在实际开发中使用编写好的控件<atlas:ScriptManager ID="ScriptManager1" runat="server" />

添加一个TextBox,用来输入用户名;一个Label,用来显示验证结果。注意到这两个控件都是ASP.NET的服务器端控件,也就是说您可以采用所见即所得的开发方式,从Toolbox中将它们拖拽到页面上,和我们熟悉的ASP.NET开发模型一样。

开发ASP.NET Atlas服务器端Extender控件——在实际开发中使用编写好的控件<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
开发ASP.NET Atlas服务器端Extender控件——在实际开发中使用编写好的控件
<asp:Label ID="Label1" runat="server"></asp:Label>

然后是本实例的核心部分,ValidateUserNameExtender的声明。在页面中输入下面的代码,指定我们的控件的属性。当然,如果你愿意,也可以将其添加到Toolbox中,并拖拽到页面上。

开发ASP.NET Atlas服务器端Extender控件——在实际开发中使用编写好的控件<dflying:ValidateUserNameExtender ID="validateUserName" runat="server">
开发ASP.NET Atlas服务器端Extender控件——在实际开发中使用编写好的控件    
<dflying:ValidateUserNameProperties CheckResultLabelID="Label1" TargetControlID="TextBox1"
开发ASP.NET Atlas服务器端Extender控件——在实际开发中使用编写好的控件        ServiceName
="UserRegisterService.asmx" MethodName="CheckUserName" ValidMessage="You can use this user name."
开发ASP.NET Atlas服务器端Extender控件——在实际开发中使用编写好的控件        InvalidMessage
="This user name has already been used, please choose another." />
开发ASP.NET Atlas服务器端Extender控件——在实际开发中使用编写好的控件
</dflying:ValidateUserNameExtender>

注意到输入的同时IDE的智能感知功能:
开发ASP.NET Atlas服务器端Extender控件——在实际开发中使用编写好的控件
属性窗口中也列出了所有可选属性,这些都大大加快了我们的开发速度:
开发ASP.NET Atlas服务器端Extender控件——在实际开发中使用编写好的控件

大功告成,浏览器中测试一下,可以使用的用户名:
开发ASP.NET Atlas服务器端Extender控件——在实际开发中使用编写好的控件

不可以使用的用户名:
开发ASP.NET Atlas服务器端Extender控件——在实际开发中使用编写好的控件

ValidateUserNameExtender和本示例程序的代码可以在此下载:https://files.cnblogs.com/dflying/ValidateUserName.zip

相关文章:

  • 2022-03-10
  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2021-12-02
猜你喜欢
  • 2021-12-07
  • 2021-09-05
  • 2021-07-03
  • 2021-11-08
  • 2021-08-07
  • 2021-11-27
  • 2022-12-23
相关资源
相似解决方案