ASP.Net中程序构架与程序代码的分离 2
下面是用户控件显示程序中所使用的用户控件的具体内容:
Header.ascx(Header用户控件)
<Script Language="C#" Runat="Server">
private void AdCreated(Object src,AdCreatedEventArgs e)
{
lblAdText.Text = e.AlternateText;
}
</script>
<asp:AdRotator id="ad" AdvertisementFile="..\AdBanners\ad.xml" BorderWidth="0"
OnAdCreated="AdCreated" runat="server" /><br>
当前广告链接:<asp:Label id="lblAdText" ForeColor="red" runat="server" />
Logon.ascx(Logon用户控件)
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Data.SqlClient" %>
<Script Language="C#" Runat="Server">
protected string strConnString = "server=(local)\\Feidao;database=aspcn;Trusted_Connection=yes";
//定义UserControl的属性
public string UserName
{
get
{
return tbUserName.Text;
}
set
{
tbUserName.Text = value;
}
}
public string Password
{
get
{
return tbPasswd.Text;
}
set
{
tbPasswd.Text = value;
}
}
//事件处理
private void Submit_Click(Object sender,EventArgs e)
{
SqlConnection MyConn = new SqlConnection(strConnString);
MyConn.Open();
string strUserName,strPassword,strSelect;
strUserName = tbUserName.Text;
strPassword = tbPasswd.Text;
strSelect = "select * from bbs_user where id='"+strUserName+"' and&nb
sp;password='"+
strPassword+"'";
SqlCommand MyComm = new SqlCommand(strSelect,MyConn);
SqlDataReader dr = MyComm.ExecuteReader();
if(dr.Read())
{
//登陆成功
lblMsgShow.Text = "登陆成功";
Session["UserName"] = dr["id"].ToString();
Session["Purview"] = dr["purview"].ToString();
}
else
{
//登陆不成功
lblMsgShow.Text = "登陆不成功";
}
dr.Close();
MyConn.Close();
}
</script>
<table>
<tr><td colspan="2" align="center"><b>登陆窗口</b></td></tr>
<tr><td colspan="2" align="center"><asp:Label id="lblMsgShow" ForeColor="re 《ASP.Net中程序构架与程序代码的分离 2(第4页)》