当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > C#Web应用程序入门经典学习笔记之一

ASP.NET
FreeTextBox(版本3.1.6)在ASP.Net 2.0中使用方法
.NET 常用功能和代码小结
在 .NET Framework 2.0 中未处理的异常导致基于 ASP.NET 的应用程序意外退出
asp.net IList查询数据后格式化数据再绑定控件
asp.net sql存储过程
asp.net 简单实现禁用或启用页面中的某一类型的控件
asp.net(c#)获取内容第一张图片地址的函数
The remote procedure call failed and did not execute的解决办法
ASP.NET 在线文件管理
asp.net 读取并修改config文件实现代码
ASP.NET Cookie 操作实现
asp.net Silverlight中的模式窗体
Silverlight中动态获取Web Service地址
asp.net Silverlight应用程序中获取载体aspx页面参数
asp.net 水晶报表隔行换色实现方法
asp.net 获取Gridview隐藏列的值
手动把asp.net的类生成dll文件的方法
asp.net 使用ObjectDataSource控件在ASP.NET中实现Ajax真分页
动态指定任意类型的ObjectDataSource对象的查询参数
asp.net Md5的用法小结

ASP.NET 中的 C#Web应用程序入门经典学习笔记之一


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-11   浏览: 56 ::
收藏到网摘: n/a

最近看了《Beginning C# Web Applications Wtith Visual Studio .Net 》。感觉这本书在一些细节方面写的不错,特做笔记,为后来者提供一些或许有用的东东。今天先写出来一些,年前正确整理完。
当前日期:
Lbll.Text = DateTime.Now.ToLongDataString();
This.controls.Add(lbl);
URL:
HyperLink reg = new HyperLink();
Reg.Text = “Register;
Reg.NavigateUrl = Context.Request.ApplicationPath + “Myfirst.aspx”;
判断用户授权:
Context.User.Identity.IsAuthenticated;
表格相关:
1. 新建一图片img
2. img添加到cell
3. cell添加到row
4. row添加到Table
5. Table添加到PlaceHolder
Table tb = new Table();
TableRow row = new TableRow();
Image img = new Image();
img.ImageUrl = "/upload/tech/20091011/20091011143308_6d0f846348a856321729a2f36734d1a7.gif";
img.ImageAlign = ImageAlign.Middle;
img.Width = new Unit(24, UnitType.Pixel);
img.Height = new Unit(24, UnitType.Pixel);
cell = new TableCell();
cell.Controls.Add(img);
row.Cells.Add(cell);
HyperLink lnk = new HyperLink();
lnk.Text = "News";
lnk.NavigateUrl = "News.aspx";
row.Cells.Add(cell);
tb.Rows.Add(row);
phNav.Controls.Add(tb);
将已验证身份的用户重定向回最初请求的URL
public static void RedirectFromLoginPage(string userName,bool createPersistentCookie);
参数
userName
用于 Cookie 身份验证的用户名称。这不需要映射到帐户名称,并将由 URL 身份验证使用。
createPersistentCookie
指定是否应当发出持久性 Cookie(跨浏览器会话保存的 Cookie)。
标准数据库操作1
String sql;
SqlCommand cmd;
SqlConnection conn;
Sql = “insert into …”;
conn = new SqlConnection (“data source = (local); initial catalog = caoxicao;userid = sa”);
cmd = new SqlCommand (sql,conn);
conn.open();
cmd.ExecuteNonQuery();
标准数据库操作2
SqlConnection conn;
SqlCommand cmd;
SqlDataReader reader;
string sql;
sql = “select * from TableName”;
conn = new SqlConnection (“data source = (local); initial catalog = caoxicao;userid = sa”)
cmd = new SqlCommand(sql,conn);
conn.open();
reader = cmd.ExecuteReader();
可以用reader的Read()方法判断是否真的返回了值
If (reader.Read())
...{
This.Email.Text = reader[“Email”].ToString();
}
DataSet 基本操作
DataSet dsCaoxicao;
String sql;
SqlConnection conn;
SqlDataAdapter adPlaces;
conn = new SqlConnection (“data source = (local); initial catalog = caoxicao;userid = sa”)
adPlaces = new SqlDataAdapter(sql,conn);
dsCaoxiCao = new DataSet();
conn.Open();
adPlaces.Fill(dsCaoxiCao,”Places”);