您的位置:首页 > 编程语言 > ASP

学习ASP.NET

2016-07-16 22:14 525 查看
/*
第二章和第三章
*/

学习了内置对象

服务器
sessio["name"]=任意数据类型值;
application["name"]=任意数据类型值;

viewstate[""]=值; //用于存放回传页面之前的数据

客户端
cookie

httpcookie hc=new httpcookie("name");
hc.value=字符串;
hc.expries=datetime.now.adddays(天数);
httpcontext.current.response.cookie.add(hc);
//取出cookie
<pre name="code" class="csharp">httpcontext.current.request.cookie["name"];
//失效
hc.expries=datetime.now.adddays(-1);


<span style="color:#000066;"> /* 在js中 动态添加标签元素 */ var t = document.getElementById("t1"); var l = document.getElementsByTagName("input").length; var tr = document.createElement("tr"); var td1 = document.createElement("td"); var td2 = document.createElement("td");
var i = document.createElement("input"); i.setAttribute("type", "text"); i.setAttribute("name", "d" + (l + 3)); td2.appendChild(i); td1.appendChild(document.createTextNode("明细项"+(l-5))); tr.appendChild(td1); tr.appendChild(td2); // var b=document.createElement("br");
t.appendChild(tr); // t.applyElement("明细项"+l+3); // t.appendChild(i);</span>

/*

第四章 ASP.NET服务器控件

*/

<pre name="code" class="html">RadioButtonList 控件:


<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Text="男" Selected="true">
</asp:ListItem>
<asp:ListItem Text="女"></asp:ListItem>
</asp:RadioButtonList>
--后台取值:
string  sex = RadioButtonList1.SelectedItem.Text;


--关于在网页中 插入日历(一些js代码 和HTML代码)
<tr>
<td>出生日期:</td>
<td>
<input type="text" id="birth" runat="server"/>
<img onclick="WdatePicker({el:$dp.$('birth')})"
src="/js/My97DatePicker/skin/datePicker.gif"
_fcksavedurl="My97DatePicker/skin/datePicker.gif"
width="16" height="22" style="cursor:pointer"
align="absmiddle" />
</td><asp:Label ID="Label4" runat="server" Text="请选择出生日期" Visible="false"></asp:Label>
</tr>
<tr>
后台得到后可计算年龄:

TimeSpan span = DateTime.Now - birthday; //得到天数,时分秒,毫秒差

DropDownList1控件:

<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text="老板" Selected="True"></asp:ListItem>
<asp:ListItem Text="It"></asp:ListItem>
<asp:ListItem Text="设计师"></asp:ListItem>
<asp:ListItem Text="老师"></asp:ListItem>
<asp:ListItem Text="医生"></asp:ListItem>
</asp:DropDownList>
 
后台使用: string work = DropDownList1.SelectedItem.Text;

--CheckBoxList1控件:
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem Text="篮球"></asp:ListItem>
<asp:ListItem Text="足球"></asp:ListItem>
<asp:ListItem Text="看电影"></asp:ListItem>
<asp:ListItem Text="旅游"></asp:ListItem>
<asp:ListItem Text="听音乐"></asp:ListItem>
</asp:CheckBoxList>


后台使用:
if (CheckBoxList1.Items.Count > 0)
{
for(int i=0;i<CheckBoxList1.Items.Count;i++){

if(CheckBoxList1.Items[i].Selected){
hobby.Add(CheckBoxList1.Items[i].Text);

}
}

}


--FileUpload1控件(装图片或者文件)
<asp:FileUpload ID="FileUpload1" runat="server" />


后台使用:
if (FileUpload1.HasFile)
{
string filename = "/images/"+FileUpload1.FileName;

string fullname = Server.MapPath("~");
fullname += filename;
FileUpload1.SaveAs(fullname);
ui.Photo = filename;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  javascript