正確的做法很簡單,但筆者卻走了不少彎路。所以在這里記錄下正確的做法。
首先新建網站,選擇aps.net空網站,在添加新項,選擇web窗體,會創建aspx和cs文件,其中aspx是asp.net的文件,其中可寫界面,也可用工具箱拖動控件,cs則是c#文件,其中寫控制控件的事件的方法。
接下來記錄使用到的控件和需要注意的地方:
1.HyperLink asp中超鏈接的控件,屬性NavigateUrl說明跳轉的目標url。
2.OnClick事件添加在控件中后,在cs文件中實現方法,即可實現點擊事件。
3.界面跳轉,Server.Transfer("~.aspx");
4.彈出提示框, Page.ClientScript.RegisterStartupScript(this.GetType(),"Scripts", "<Script>alert('Welcom! ');</Script>");
5.Response.Write(“ ”) 在當前頁面返回信息。
6.頁面間數據的交互:
在第一個頁面中獲取數據:Session["name"] = Tex_name.Text;
第二個頁面:Lab_name.Text="姓名: "+ Session["name"].ToString(); //接收從上一頁面傳來的數據
7.獲取復選框的數據:
foreach(ListItem course in Checkbox_course.Items) //獲得復選框的數據
{
if (course.Selected)
texcourse =course.Text + " "+texcourse;
}
8.placehloder的使用:
Plahodchebox.Controls.Add(new LiteralControl(choice.Text + ": " + "深圳 ")); 開始時不顯示,運行中動態顯示。
dropdownlist和checkbox點擊事件允許返回的屬性:AutoPostBack="True",OnSelectedIndexChanged=“”; 其中的方法在cs中實現。
根據checkbox被選中的文本相應不同的事件,使用foreach和if結構,代碼為:
Plahodchebox.Controls.Add(new LiteralControl("姓名:" + DropName.SelectedItem.Text + " " + " 性別: 女 " + " 生日: 1995-4-5"));
foreach (ListItem choice in ChkDisplay.Items) //獲得復選框的數據
{
if (choice.Selected)
{
if (choice.Text == "住址")
{
} }
9.css的使用
在<head>中加入:
<style type="text/css">
p.dash {border-style: dashed none none}
</style>
p.dash 表示此css用於p標簽,dash是classname,在需要使用的地方嵌入:<p class="dash">即可。border-styel表示邊框,dashed表示虛線。
10.label中text的設置:styel="font-weight:900" Font-size="25px"></asp:Label>