简体   繁体   English

尝试更改默认情况下使用Asp.Net WebForms模板提供的Login.aspx页的母版时发生运行时错误

[英]Runtime error when attempting to change the Master Page for the Login.aspx page given by default with the Asp.Net WebForms template

I started an Asp.Net WebForms project in Visual Studios 2015 using the WebForms template. 我使用WebForms模板在Visual Studios 2015中启动了Asp.Net WebForms项目。 However, I would now like to change the MasterPage from the default (~/Site.Master) to a master page I created from a downloaded Bootstrap template. 但是,我现在想将母版页从默认(〜/ Site.Master)更改为我从下载的Bootstrap模板创建的母版页。

The downloaded template works just find on the Webforms pages I created but I get this error when I attempt to use it with the Login page: 下载的模板可以在我创建的Webforms页面上找到,但是在尝试将其与Login页面一起使用时出现此错误:

Additional information: Control 'Email' of type 'TextBox' must be placed inside a form tag with runat=server. 附加信息:必须将类型为“文本框”的控件“电子邮件”放置在带有runat = server的表单标记中。

I have tried to create a new page without using the Master Page and I continue to get the error. 我试图在不使用母版页的情况下创建新页,但继续出现错误。 The first thing I checked was the textbook used for the email but it does have runat="server". 我检查的第一件事是用于电子邮件的教科书,但确实有runat =“ server”。 Here is a snippet of the code: 这是代码片段:

<div class="form-group" runat="server">
     <asp:Label runat="server" AssociatedControlID="Email" CssClass="col-md-2 control-label">Email</asp:Label>
     <div class="col-md-10">
          <asp:TextBox runat="server" ID="Email" CssClass="form-control" TextMode="Email" />
          <asp:RequiredFieldValidator runat="server" ControlToValidate="Email" CssClass="text-danger" ErrorMessage="The email field is required." />
     </div>
 </div>

Any help would be greatly appreciated. 任何帮助将不胜感激。 I've checked a few questions already but most deal with dynamically changing the MasterPage in the code behind (by the way, that's not the solution I'm looking for). 我已经检查了几个问题,但是大多数问题涉及在后面的代码中动态更改MasterPage(顺便说一句,这不是我要寻找的解决方案)。 Thanks. 谢谢。

As the error says, you should place your control inside a ContentPlaceHolder element. 如错误所述,您应该将控件放置在ContentPlaceHolder元素内。 See MSDN documentation for same https://msdn.microsoft.com/en-us/library/wtxbf3hh.aspx 请参阅MSDN文档以获取相同的https://msdn.microsoft.com/zh-cn/library/wtxbf3hh.aspx

In your master page your have a contentplaceholder like 在您的母版页中,您有一个内容contentplaceholder例如

    <asp:contentplaceholder id="cp1" runat="server">
    </asp:contentplaceholder>

In your Login page include master page including MasterPageFile property 在您的“ Login页面中,包括包含MasterPageFile属性的母版页

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" ...

<asp:Content ID="Content1" ContentPlaceHolderID="cp1" Runat="Server">
<asp:TextBox runat="server" ID="Email" CssClass="form-control" TextMode="Email" />
</asp:Content>

I have found the answer from this link which says: 我从这个链接中找到了答案:

*Master Pages and Themes *母版页和主题

You cannot directly apply an ASP.NET theme to a master page. 您不能直接将ASP.NET主题应用于母版页。 If you add a theme attribute to the @ Master directive, the page will raise an error when it runs. 如果将主题属性添加到@ Master指令,则该页面在运行时将引发错误。 However, themes are applied to master pages under these circumstances: If a theme is defined in the content page. 但是,在以下情况下,主题将应用于母版页:如果在内容页面中定义了主题。 Master pages are resolved in the context of content pages, so the content page's theme is applied to the master page as well. 母版页是在内容页的上下文中解析的,因此内容页的主题也适用于母版页。 If the site as a whole is configured to use a theme by including a theme definition in the pages Element (ASP.NET Settings Schema) element. 如果将站点整体配置为通过在页面元素(ASP.NET设置架构)元素中包含主题定义来使用主题。 For more information, see ASP.NET Themes and Skins.* 有关更多信息,请参见ASP.NET主题和皮肤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM