ASP.Net中程序构架与程序代码的分离
this.Controls.Add(ad);
this.Controls.Add(new LiteralControl("<br>"+"当前广告链接为:"));
//加入Label控件
lblAdText = new Label();
lblAdText.ForeColor = Color.Red;
this.Controls.Add(lblAdText);
}
private void OnAdCreated(Object sender,AdCreatedEventArgs e)
{
this.lblAdText.Text = e.AlternateText;
}
}
//接着是Logon
public class Logon : Control,INamingContainer
{
private string strConnString = "server=(local)\\Feidao;database=aspcn;Trusted_Connection=yes";
private Label lblMsgShow;
private TextBox tbUserName,tbPasswd;
public String UserName
{
get
{
return tbUserName.Text;
}
set
{
tbUserName.Text = value;
}
}
protected override void CreateChildControls()
{
//添加HTML标签
this.Controls.Add(new LiteralControl("<table><tr><td colspan=\"2\" align=\"center\"><b>登陆窗口</b></td></tr> <tr><td colspan=\"2\" align=\"center\">"));
//添加MsgShow Label控件
lblMsgShow = new Label();
lblMsgShow.ForeColor = Color.Red;
this.Controls.Add(lblMsgShow);
this.Controls.Add(new LiteralControl("</td></tr><tr><td>用户名:</td><td>"));
//添加UserName与Passwd TextBox控件
tbUserName = new TextBox();
this.Controls.Add(tbUserName);
this.Controls.Add(new LiteralControl("</td></tr><tr><td>密码:</td><td>"));
tbPasswd = new TextBox();
tbPasswd.TextMode = TextBoxMode.Password;
this.Controls.Add(tbPasswd);
this.Controls.Add(new LiteralControl("</td></tr><tr><td>"));
//添加BtnSubmit Button控件
Button btnSubmit = new Button();
btnSubmit.Text = "登陆";
btnSubmit.Click += new EventHandler(this.Submit_Click);
this.Controls.Add(btnSubmit);
this.Controls.Add(new LiteralControl("</td></tr></table>"));
}
//显示完毕
private void Submit_Click(Object sender,EventArgs e)
{
SqlConnection MyConn = new SqlConnection(strConnString);
MyConn.Open();
s