asp.net 2.0中,login登陆控件是个不错的选择,但有时需要扩展该控件,比如,在一个OA系统中,有时要选择登陆的用户所在的是集团的哪一个子公司,这样,除了用户名,密码外,还需要有个dropdownlist,设置为该集团的所有子公司名,象这样应该如何实现呢?
我们可以首先选择login control,并且将其转换为模版列,在其中加上一个dropdownlist,如下:
<asp:Login ID="Login1" runat="server" OnLoggingIn="Login1_LoggingIn">
<LayoutTemplate>
….
<asp:DropDownList id=”companies” runt=”server” …>
….
</asp:DropDownList>
….
</LayoutTemplate>
</asp:Login>
然后在login控件的Authenticate事件中,写入如下代码:
protected void Login1_ Authenticate (object sender, AuthenticateEventArgs e)
...{
string company:
DropDownList companies = Login1.FindControl("companies ") as DropDownList;
if (companies != null)
company = companies.SelectedValue;
…
//Validate the user..
e.Authenticated = true;
}