RKh
RKh

Reputation: 14161

Why a DIV is not valid within ASP tag in this code?

Below is the code of my Web Content Form. The DIV inside ASP tag shows green underline and also the text that is written in DIV tag is not visible on the Content Page.

<%@ Page Title="" Language="C#" MasterPageFile="~/Presentation_Layer/Pages/home.Master" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="live1._default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
        <asp:Label ID="lblWelcomeMessage" runat="server" ForeColor="Black">
            <div id="divProfile"> 
                This is a test.
            </div>
        </asp:Label>
</asp:Content>

Upvotes: 1

Views: 590

Answers (2)

chprpipr
chprpipr

Reputation: 2039

Ramiz's answer is correct. If you're looking for solutions, here are a few options:

<asp:Panel> renders a <div>. The id won't be easily guessable, but you can set the CssClass if you need to access it using client-side script.

Another option is that you can just do this: <div id="divProfile" runat="server"> if you want to have access to it within your codebehind. If you need to access this with client-side script, you just set the class attribute, not the CssClass attribute.

Upvotes: 0

Ramiz Uddin
Ramiz Uddin

Reputation: 4259

<asp:Label runat="server"/> renders as span tag on browser.

You cannot nest a block level element inside of an inline element. label and span are inline elements, DIV is block level.

Upvotes: 7

Related Questions