ASP.Net中程序构架与程序代码的分离
rc属性则是具体指出了使用的用户控件的文件名(用户控件均以.ascx结尾)。
用户控件的使用与普通Server控件一样:
<namespace:class ... runat="server" />
namespace表示定义的命名空间,class则是相应的类名,具体的使用例子有:
<aspcn:Logon id="MyLogon" runat="server" />
下面是用户控件显示程序中所使用的用户控件的具体内容:
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+
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 = "登陆不 《ASP.Net中程序构架与程序代码的分离(第4页)》
本文链接地址:http://www.oyaya.net/fanwen/view/168961.html
用户控件的使用与普通Server控件一样:
<namespace:class ... runat="server" />
namespace表示定义的命名空间,class则是相应的类名,具体的使用例子有:
<aspcn:Logon id="MyLogon" runat="server" />
下面是用户控件显示程序中所使用的用户控件的具体内容:
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 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 = "登陆不 《ASP.Net中程序构架与程序代码的分离(第4页)》