簡體   English   中英

為什么服務器控件放在Content標簽內時會加下划線?

[英]Why server controls are underlined when placed inside Content tags?

我有一個包含Div的Web內容表單和DropDownList類的各種服務器控件。 當我運行應用程序時,它運行良好,沒有任何錯誤,但當我查看HTML源代碼時,服務器控件是紅色下划線。 將鼠標懸停在DropDownList ,會顯示工具提示警告:

DropDownList is not a known element. This can occur if there is a compilation error in a website.

編輯

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="contentReportSchemesMenu.aspx.cs" Inherits="contentReportMenu" Title="Reports Menu" %>

<asp:Content ID="ContentReportMenu" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div id="divMenu" class="divMenu" runat="server">
        <table id="tblMenuLayout" class="Options" runat="server">
        <tr>
            <td colspan="2" class="Top">Scheme Reports Menu</td>
            <td></td>
        </tr>
            <tr>
                <td class="Left">Report Type</td>
                <td class="Right">
                        &nbsp;<asp:DropDownList ID="ddlReportType" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlReportType_SelectedIndexChanged"></asp:DropDownList>
                </td>
            </tr>        
            <tr>
                <td class="Left">Select District</td>
                <td class="Right">
                        &nbsp;<asp:DropDownList ID="ddlDistrict" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlDistrict_SelectedIndexChanged" Enabled="False"></asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td class="Left">Select Block</td>
                <td class="Right">
                    &nbsp;<asp:DropDownList ID="ddlBlock" runat="server" AutoPostBack="true" Enabled="False" OnSelectedIndexChanged="ddlBlock_SelectedIndexChanged"></asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align:center">
                    <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" Enabled="False" />
                    &nbsp;</td>
                <td></td>
            </tr>
        </table>
    </div>
</asp:Content>

快速谷歌搜索很快找到了解決方案:從“C:\\ Documents and Settings [Username] \\ Application Data \\ Microsoft \\ VisualStudio \\ 9.0 \\ ReflectedSchemas”文件夾(或“... \\ VisualStudio \\ 8.0 \\ ...”)中刪除文件Studio 2005)在Windows XP中。 在Windows 7中,它位於“C:\\ Users {User Profile} \\ AppData \\ Roaming \\ Microsoft ... etc”下。 還要記住,路徑的“VisualStudio”部分將根據安裝的版本而有所不同。

我關閉了Visual Studio(對於會影響IDE的更改總是很好的想法),刪除文件然后重新打開項目。 警告消失了。

我在以下網址找到了對此解決方案的引用: http//forums.asp.net/t/1205528.aspx http://blogs.msdn.com/mikhailarkhipov/archive/2005/04/21/410557.aspx

僅供參考,我在谷歌使用的搜索詞是“不支持元素”。

我不知道為什么會發生這種情況,但我知道在網絡環境中發生了一些有趣的域名配置文件。

您收到此錯誤,因為該table正在服務器上運行,但trtd元素不是。 在表元素上指定runat="server"時,它也期望子元素也在服務器上運行。

有兩種簡單的方法可以驗證這一點:

  1. 從表聲明中刪除runat="server" ;
  2. 將DropDownList(s)放在表格之外

嘗試這兩個選項之一,看看它是否解決了問題。

編輯

確保內容表單上的ContentPlaceHolderID與母版頁中相應內容區域的ID相匹配。 如果這不能解決您的問題,請嘗試創建新的內容表單,應用上面的建議,並在內容區域中向表單添加控件。 如果沒有錯誤,那么您就知道問題出在您的標記中。

嘗試刪除架構緩存。 為此,請關閉Visual Studio並刪除以下目錄中的所有文件:

C:\\ Users \\用戶名\\ AppData \\漫游\\微軟\\ VisualStudio的\\ 10.0 \\ ReflectedSchemas

刪除文件后,再次打開Visual Studio,應該修復問題。

您說"when I view the HTML source, the Server controls are red underlined" ,但HTML源代碼不能包含像DropDownList這樣的元素,因為這是作為HTML Select標記生成的ASP.NET控件。 考慮到使用模式清理的常見解決方案沒有幫助你或許在另一個地方出現問題......我將嘗試假設你使用一些不了解ASP.NET的第三方編輯器打開ASPX / ASCX文件本身控制,我是對的嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM