<SELECT id="selOpSys" size="1" >
<OPTION>Windows 95</OPTION>
<OPTION>Windows 98</OPTION>
<OPTION>Windows NT4</OPTION>
<OPTION>Windows 2000</OPTION>
</SELECT>
加上runat=Server就变成服务器端控件
<SELECT id="selOpSys" size="1" runat="server">
<OPTION>Windows 95</OPTION>
<OPTION>Windows 98</OPTION>
<OPTION>Windows NT4</OPTION>
<OPTION>Windows 2000</OPTION>
</SELECT>
服务器端控件能在服务器端脚本中被自由运用
传统的asp代码
If Len(Request.Form("selOpSys")) > 0 Then
strOpSys = Request.Form("selOpSys")
strName = Request.Form("txtName")
Response.Write("You selected @#" & strOpSys _
& "@# for machine @#" & strName & "@#.")
End If
asp+代码
If Len(selOpSys.value) > 0 Then
Response.Write("You selected @#" & selOpSys.value _
& "@# for machine @#" & txtName.value & "@#.")
End If
一个服务器端的form 代码
<FORM runat="server">
Machine Name:
<INPUT type="text" id="txtName" runat="server">
<P />
Operating System:
<select id="selOpSys" size="1" runat="server">
<OPTION>Windows 95</OPTION>
<OPTION>Windows 98</OPTION>
<OPTION>Windows NT4</OPTION>
<OPTION>Windows 2000</OPTION>
</SELECT>
<P />
<INPUT type="submit" value="Submit">
</FORM>
运行后将自动被解释成客户端代码
<HTML>
<BODY>
You selected @#Windows 98@# for machine @#tizzy@#.
<FORM name="ctrl0" method="post"
action="pageone.aspx" id="ctrl0">
<INPUT type="hidden" name="__VIEWSTATE"
value="a0z1741688109__x">
Machine Name:
<INPUT type="text" id="txtName"
name="txtName" value="tizzy">
<P />
Operating System:
<SELECT id="selOpSys" size="1" name="selOpSys">
<OPTION value="Windows 95">Windows 95</OPTION>
<OPTION selected value="Windows 98">
Windows 98</OPTION>
<OPTION value="Windows NT4">Windows NT4</OPTION>
<OPTION value="Windows 2000">Windows 2000</OPTION>
</SELECT>
<P />
<INPUT type="submit" value="Submit">
</FORM>
</BODY>
</HTML>
三、服务器端事件
服务器端控件具有事件,可以像操作客户端事件一样操作服务器端事件,asp+自动翻译服务器端事件到客户端
举例:
onserverclick事件
<HTML>
<BODY>
<SCRIPT language="VB" runat="server">
Sub ShowValues(Sender As Object, Args As EventArgs)
divResult.innerText = "You selected @#" _
& selOpSys.value & "@# for machine @#" _
& txtName.value & "@#."
End Sub
</SCRIPT>
<DIV id="divResult" runat="server"></DIV>
<FORM runat="server">
Machine Name:
<INPUT type="text" id="txtName" runat="server">
<P />
Operating System:
<select id="selOpSys" size="1" runat="server">
<OPTION>Windows 95</OPTION>
<OPTION>Windows 98</OPTION>
<OPTION>Windows NT4</OPTION>
<OPTION>Windows 2000</OPTION>
</SELECT>
<P />
<INPUT type="submit" value="Submit"
runat="server" onserverclick="ShowValues">
</FORM>
</BODY>
</HTML>
相关讨论地址