11.22
html服务器控件
其实就是html控件的基础上加上runat="server"所构成的控件。
它们的主要区别是运行方式不同,html控件运行在客户端,而html服务器控件是运行在服务器端的。
web服务器控件
也称asp.net服务器控件,是Web Form编程的基本元素,也是asp.net所特有的。
它会按照client的情况产生一个或者多个html控件,而不是直接描述html元素
web服务器控件和html服务器控件有什么区别
1、Asp.net服务器控件提供更加统一的编程接口,如每个Asp.net服务器控件都有Text属性。
2、隐藏客户端的不同,这样程序员可以把更多的精力放在业务上,而不用去考虑客户端的浏览器是ie还是firefox,或者是移动设备。
3、Asp.net服务器控件可以保存状态到ViewState里,这样页面在从客户端回传到服务器端或者从服务器端下载到客户端的过程中都可以保存。
4、事件处理模型不同,Html标签和Html服务器控件的事件处理都是在客户端的页面上,而Asp.net服务器控件的事件处理则是在服务器上
添加DAL层
*/
/// <summary>
/// 添加
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
public static int Insert(ClassInfo info)
{
var sql = "insert into ClassInfo values(@name , @Comment)";
SqlParameter[] sqlParameters = new SqlParameter[]
{
new SqlParameter("@name",info.Name),
new SqlParameter("@Comment",info.Comment)
};
return SqlHelper.NonQuery(sql,sqlParameters);
}
BLL层
/// <summary>
/// 添加
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
public static int Insert(ClassInfo info)
{
return ClassInfoDAL.Insert(info);
}
UI层
/// <summary>
/// 添加
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
var name = TextBox1.Value;
var commet = TextBox2.Text;
Text.model.ClassInfo info = new Text.model.ClassInfo()
{
Name = name,
Comment=commet
};
if (BLL.ClassInfoBLL.Insert(info)>0)
{
Response.Write("<script>alert('添加成功');location='ClassInfo.aspx'</script>");
//Response.Redirect("ClassInfo.aspx");
}
}

浙公网安备 33010602011771号