必须放置在表单标签内使用runat = server [英] Must be Placed Inside a Form Tag With runat=server
问题描述
接收到以下错误:
'TextBox'类型的控件'HeadContent_CareersViewPosting_txtFirstName'必须放置在窗体标签中,并且runat =服务器。
已经尝试了建议这里,这里和这里并且没有结果。仍收到完全相同的信息。
<%@ Control Language =C#AutoEventWireup =trueCodeBehind = Careers查看Posting.ascx.csInherits =ascxStagingApplication.Careers.Careers_View_Posting%>
< asp:Panel ID =pnlResumerunat =server>
< table ID =tblMainrunat =server>
< tr>
< td>
< asp:Label ID =lblFirstNamerunat =serverText =* First Name>< / asp:Label>
< / td>
< td>
< asp:TextBox ID =txtFirstNamerunat =server>< / asp:TextBox>
< / td>
< / tr>
< tr>
< td>
< asp:Label ID =lblLastNamerunat =serverText =* Last Name>< / asp:Label>
< / td>
< td>
< asp:TextBox ID =txtLastNamerunat =server>< / asp:TextBox>
< / td>
< / tr>
< tr>
< td>
< asp:Label ID =lblEmailrunat =serverText =* Email>< / asp:Label>
< / td>
< td>
< asp:TextBox ID =txtEmailrunat =server>< / asp:TextBox>
< / td>
< / tr>
< tr>
< td>
< asp:Label ID =lblResumerunat =serverText =* Resume>< / asp:Label>
< / td>
< td>
< asp:FileUpload ID =fupResumerunat =server/>
< / td>
< / tr>
< tr>
< td>
< asp:Button ID =btnSubmitrunat =serverText =Submit/>
< / td>
< / tr>
< / table>
< / asp:面板>
用户控件目前正放置在虚拟网页上进行测试。这是'虚拟'页面代码。
<%@ Page Title =Language =C#MasterPageFile = 〜/ Site.MasterAutoEventWireup =trueCodeBehind =页面职业查看Posting.aspx.csInherits =ascxStagingApplication.Careers.Page_Careers_View_Posting%>
<%@ Register Src =〜/ Careers / Careers查看Posting.ascxTagPrefix =uc1TagName =CareersViewPosting%>
< asp:Content ID =Content1ContentPlaceHolderID =HeadContentrunat =server>
< uc1:CareersViewPosting runat =serverid =CareersViewPosting/>
< / asp:Content>
在ASPNet webforms中,所有内容都需要在表单中运行所有服务器控件都必须出现在< form>
标签中,< form>
标签必须包含 runat =server
属性。 runat =server
属性表示应该在服务器上处理表单。它还表明封闭的控件可以被服务器脚本访问:
< form runat =server>
... HTML +服务器控件
< / form>
在您的虚拟页面中,请尝试以下操作以允许服务器控件运行。
<%@ Page Title =Language =C#MasterPageFile =〜/ Site.MasterAutoEventWireup =trueCodeBehind =Page Careers查看Posting.aspx.csInherits =ascxStagingApplication.Careers.Page_Careers_View_Posting%>
<%@ Register Src =〜/ Careers / Careers查看Posting.ascxTagPrefix =uc1TagName =CareersViewPosting%>
< form runat =server>
< asp:Content ID =Content1ContentPlaceHolderID =HeadContentrunat =server>
< uc1:CareersViewPosting runat =serverid =CareersViewPosting/>
< / asp:Content>
< / form>
另外 - 检查您的〜/ Site.Master文件是否包含< form runat =server>
如果不是这样的话,那么这将是您拥有所有封闭表单标记的地方。
您可以在这里阅读更多信息: http://www.w3schools.com/aspnet/aspnet_forms。 asp
I have been attempting this all morning with no results. I can't seem to figure out what I'm doing wrong. I have checked out the two links (among many other unhelpful links) and have yet to solve my issue. This is a WebUserControl...
Receiving the following error: Control 'HeadContent_CareersViewPosting_txtFirstName' of type 'TextBox' must be placed inside a form tag with runat=server.
Already attempted the suggestions here, here and here and no results. Still received the exact same message. Some new suggestions would be greatly appreciated!
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Careers View Posting.ascx.cs" Inherits="ascxStagingApplication.Careers.Careers_View_Posting" %>
<asp:Panel ID="pnlResume" runat="server">
<table ID="tblMain" runat="server">
<tr>
<td>
<asp:Label ID="lblFirstName" runat="server" Text="* First Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblLastName" runat="server" Text="* Last Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblEmail" runat="server" Text="* Email"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblResume" runat="server" Text="* Resume"></asp:Label>
</td>
<td>
<asp:FileUpload ID="fupResume" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit"/>
</td>
</tr>
</table>
</asp:Panel>
The user control is currently being placed onto a dummy webpage for testing. Here is the 'dummy' page code.
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Page Careers View Posting.aspx.cs" Inherits="ascxStagingApplication.Careers.Page_Careers_View_Posting" %>
<%@ Register Src="~/Careers/Careers View Posting.ascx" TagPrefix="uc1" TagName="CareersViewPosting" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<uc1:CareersViewPosting runat="server" id="CareersViewPosting" />
</asp:Content>
In ASPNet webforms - everything needs to run within a form tag.
All server controls must appear within a <form>
tag, and the <form>
tag must contain the runat="server"
attribute. The runat="server"
attribute indicates that the form should be processed on the server. It also indicates that the enclosed controls can be accessed by server scripts:
<form runat="server">
...HTML + server controls
</form>
In your dummy page try the following to allow the server controls to run.
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Page Careers View Posting.aspx.cs" Inherits="ascxStagingApplication.Careers.Page_Careers_View_Posting" %>
<%@ Register Src="~/Careers/Careers View Posting.ascx" TagPrefix="uc1" TagName="CareersViewPosting" %>
<form runat="server">
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<uc1:CareersViewPosting runat="server" id="CareersViewPosting" />
</asp:Content>
</form>
Also - check that your ~/Site.Master file contains the <form runat="server">
if not -a s it would be fairly typical for that to be the place to have your all enclosing form tag.
You could read more here: http://www.w3schools.com/aspnet/aspnet_forms.asp
这篇关于必须放置在表单标签内使用runat = server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!