<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</body>
</html>很明显,少了form的原因,原因是我想去掉页面中隐藏的input而去掉了form:
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNzgzNDMwNTMzZGSeyZbEJyAclc40+nGVQK0EIblvEA==" />
加上form再测试就正常了:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
[color=Red]<form id="form1" runat="server">[/color]
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
[color=Red]</form>[/color]
</body>
</html>后来又发现并非所有服务控件都要放在form中,总结了下:
必须放在具有 runat=server 的窗体标记内的控件:
TextBox
Button
LinkButton
ImageButton
DropDownList
ListBox
CheckBox
RadioButton
HiddenField
Calendar
FileUpload
Wizard
GridView
DetailsView
FormView
可以不放在具有 runat=server 的窗体标记内的控件:
Label
HyperLink
CheckBoxList
RadioButtonList
Image
ImageMap
Table
BulletedList
Literal
AdRotator
Xml
MultiView
Panel
PlaceHolder
View
Substitution
Localize
DataList
ListView
Repeater
SqlDataSource
AccessDataSource
评论(0)
暂无评论。