为什么此代码中的 ASP 标记内的 DIV 无效?

发布于 2024-10-02 09:50:28 字数 575 浏览 2 评论 0原文

下面是我的网络内容表单的代码。 ASP 标记内的 DIV 显示绿色下划线,并且 DIV 标记中写入的文本在内容页上不可见。

<%@ 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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枕花眠 2024-10-09 09:50:28

在浏览器上呈现为 span 标记。

您不能将块级元素嵌套在 inline 元素内。 标签span
内联元素,DIV是块级元素。

<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.

沫离伤花 2024-10-09 09:50:28

拉米兹的回答是正确的。如果您正在寻找解决方案,这里有一些选项:

呈现

。 id 不容易猜到,但如果需要使用客户端脚本访问它,可以设置 CssClass。

另一种选择是,如果您想在代码隐藏中访问它,您可以这样做:

。如果您需要使用客户端脚本访问它,则只需设置 class 属性,而不是 CssClass 属性。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文