Why Do I Get the Error Message "Element 'Style' Cannot Be Nested Within Element 'Style'"

Why do I get the error message Element 'style' cannot be nested within element 'style'?

The style element cannot be nested under the <body> or child elements of the <body>, instead it should go to the <head> element of the page.

If you try to override the styles like this, they get inserted into the default section of your layout page by @RenderBody(), which I assume is inside the <body> of the layout page, while the default styles still stay in the <head>.

The proper way to override some part of the layout page from the content page would be something along these lines, using Razor sections:

_layout.cshtml

<head>
@if (IsSectionDefined("Style"))
{
@RenderSection("Style");
}
else
{
<style type="text/css">
/* Default styles */
</style>
}
</head>
<body>
@RenderBody()
...

page.cshtml

@{        
Layout = "layout.cshtml";
}
@section Style
{
<style type="text/css">
#main
{
height: 400px;
}
</style>
}
<!-- Body content here -->
...

Now if the Style section is defined on the content page, its contents will override the defaults from the layout page.

I suggest you read more on Razor layouts and sections. A nice article on this by ScottGu can be found here.

Regarding Visual Studio markup validation warnings

Visual Studio has a problem when markup that makes up a single page is being split up between different files like this. In most cases there is no way for Visual Studio (or any such IDE for that matter) to know how the different page fragments will be dynamically put together in the end. So usually you can't avoid some of these warnings on a project.

Personally I would ignore the warnings if I know what I'm doing and the resulting pages pass the markup validation (http://validator.w3.org/).

If you really want to hide the warnings, you need to disable the appropriate validation options in Visual Studio. E.g. for HTML in Visual Studio 2012 this can be done in Tools > Options > Text Editor > HTML > Validation.

Element 'div' cannot be nested within element 'ul'

The warning is, well, a warning. Your page is displayed correctly only because the browser is not too strict on the HTML rules, but that may change in the future. For that reason, you should try to keep your HTML compliant and take the warnings seriously. In this case, I would suggest to replace the <div> with <li> tags and style them to prevent the margins and bullets (I assume that's why you're using <div> instead of <li> in the first place).

To achieve what you want, apply this CSS style to your list:

.your-ul {
list-style: none;
}

.your-ul li {
position:relative;
margin-left: 0;
display: inline-block;
}

Your HTML/ASPX code would look like this:

<ul class="your-ul">
<li><asp:LinkButton ID="lbtnFirst" runat="server" CausesValidation="false" OnClick="lbtnFirst_Click">Ilk</asp:LinkButton></li>
<li><asp:LinkButton ID="lbtnPrevious" runat="server" CausesValidation="false" OnClick="lbtnPrevious_Click"> << </asp:LinkButton></li>
</ul>

Validation (XHTML 1.0 Transitional): Element 'html' cannot be nested within element 'div'

Your code shows you are:

    <%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master"....
  1. using a master page (which is where the HTML declaration is)

    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
  2. using the content page placeholder to add and entire HTML document - which you shouldn't do.

    • as stated, the master page is where HTML declarations go
    • ASP.net content sections are for content only.

Element 'script' cannot be nested inside element html

It should be inside body tag. So move one line up.

How to solve : the element div cannot be nested within the element 'updatepanel'

An updatepanel can contain a ContentTemplate , so add ContentTemplate like this :

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div style="overflow:scroll">
<asp:GridView ID="GridViewHome" runat="server" Width="100%" AutoGenerateColumns="false" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4" OnPageIndexChanging="GridViewHome_PageIndexChanging" PageSize="30" ShowFooter="True">

<Columns>

<asp:TemplateField>
<HeaderTemplate>Options</HeaderTemplate>
<ItemTemplate>
<div style="width:100%"> <asp:HyperLink ID="HyperLink1" NavigateUrl='<%#"/RPT/WebForm1.aspx?order_id=" +Eval("Request number")+"&DEPT ID=" +Eval("DEPT ID")+"&Test Id=" +Eval("Test Id")+"&Culture=" +Eval("Culture")%>' runat="server">Print Result</asp:HyperLink></div>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField>
<HeaderTemplate>Patient MRN#</HeaderTemplate>
<ItemTemplate>
<div style="width:100%"> <asp:Label ID="lblpatient" runat="server" Text='<%# Eval("Patient No") %>'></asp:Label></div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Patient Name</HeaderTemplate>
<ItemTemplate>
<div style="width:100%"> <asp:Label ID="lblname" runat="server" Text='<%# Eval("Patient Name") %>'></asp:Label></div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Order Number</HeaderTemplate>
<ItemTemplate>
<div style="width:100%"> <asp:Label ID="lblorder" runat="server" Text='<%# Eval("Request number") %>'></asp:Label></div>
</ItemTemplate>
</asp:TemplateField>

</Columns>

</asp:GridView>
</div>
</ContentTemplate>
</asp:UpdatePanel>

Is element ‘ul’ cannot be nested within element ‘ol’? (i am getting this error from xhtml validator) help pls

The <ul> inside needs to be inside an li, so either make a new li or un-close the first one.

element.style is undefined

It can not be able to map your board1 and board2 that's why it is give an error:

 function siteChange() {
var div1 = document.getElementById("board1");//change this
var div2 = document.getElementById("board2");//change this
if (div1.style.visibility == "collapse") {

div2.style.visibility = "collapse";
div1.style.visibility = "visible";
} else {
div1.style.visibility = "collapse";
div2.style.visibility = "visible";

}
}

Now its work for you.

asp.net error form cannot be nested within element form?

If your <asp:ContentPlaceHolder ID="MainContent" > control is, itself, inside of a form element, then you shouldn't place a form inside of the asp:content control as you should not have nested forms.

From the HTML5 working draft:

4.10.3 The form element

Content model:

Flow content, but with no form element descendants.

UPDATE

See the question A page can have only one server-side Form tag:

Master pages should not contain form tags in general because they are meant to be used only as the base layout of your content page.

Try to restructure your project using these guidelines:

  • Only add form elements to aspx pages
  • Add main content to MasterPage from pages
  • Add any content that needs to be nested within a form to a UserControl that is placed within a page.

Element 'a' cannot be nested inside element 'iframe'

The width and height attributes do not take units (except %). Therefore:

... width="200" height="461" ...

For the second problem: The error is quite clear. You cannot have an <a> tag within an iframe. You are only allowed to have text inside it. For more details, see here.



Related Topics



Leave a reply



Submit