控件必须放在具有 runat=server 的窗体标记内 解决方法
类型“TextBox”的控件“txt_UserName”必须放在具有 runat=server 的窗体标记内。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息:
System.Web.HttpException: 类型“TextBox”的控件“txt_UserName”必须放在具有 runat=server 的窗体标记内。
源错误:
执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。
堆栈跟踪:
[HttpException (0x80004005): 类型“TextBox”的控件“txt_UserName”必须放在具有 runat=server 的窗体标记内。]
System.Web.UI.Page.VerifyRenderingInServerForm(Control control) +8775651
System.Web.UI.WebControls.TextBox.AddAttributesToRender(HtmlTextWriter writer) +48
System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter writer) +20
System.Web.UI.WebControls.TextBox.Render(HtmlTextWriter writer) +20
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266
代码:
<script language="javascript">
function check()
{
if(Form1.txt_UserName.value=="")
{
alert("登陆用户名不能为空!");
Form1.txt_UserName.focus();
return false;
}
if(Form1.txt_Password.value=="")
{
alert("密码不能为空!");
Form1.txt_Password.focus();
return false;
}
else
__doPostBack('btn_OK','');
}
function OK()
{
if(confirm("添加成功!"))
{
return true;
}
else
{
return false;
}
}
function keydown()
{
if(event.keyCode==13)
{
check();
}
}
</script>
</HEAD>
<body leftMargin="0" topMargin="0" MS_POSITIONING="GridLayout">
<form id="Form1" onsubmit="javascript:return checkInput(this);" method="post" runat="server">
<table cellSpacing="0" cellPadding="0" width="100%" bgColor="#f1f1f1" border="0">
<tr>
<td height="46"><IMG height="45" src="../images/subtitle_info.gif" width="180"></td>
</tr>
</table>
<table cellSpacing="0" cellPadding="0" width="100%" bgColor="#f1f1f1" border="0">
<tr>