未定义FormView上的命名空间前缀asp-我的页面指令是什么?

时间:2019-01-29 16:31:02

标签: html asp.net forms

使用Microsoft Expression Web 4,我创建了一个简单的网页,在其中使用ASP连接来连接到本地Access DB。下面(底部)是整个页面的源代码,可以很好地工作。

当我直接浏览此网页(ASPX页)时,一切正常/有效。

但是,当我从其他网页导航到此页面时,会出现问题。浏览器指出此页面包含错误:

  

未定义FormView上的命名空间前缀asp

在此之下,提到了另一个错误,指出:

  

属性值中不允许使用转义的'<'

由于我对ASP缺乏经验,所以我没有意识到我一开始就需要页面指令。但是,我的页面指令应该是什么?

我的页面称为“进行Booking.aspx”

全部是HTML / CSS和部分JavaScript。这是整个页面。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!-- #BeginTemplate "BookingTemplate.dwt" -->


<head>
<meta content="en-gb" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<!-- #BeginEditable "doctitle" -->
<title>Untitled 1</title>
<!-- #EndEditable -->
<style type="text/css">

.auto-style1 {
    font-family: Arial, Helvetica, sans-serif;
    font-size: x-large;
}
.auto-style2 {
    text-align: center;
}
.auto-style3 {
    text-align: center;
    font-size: xx-large;
    font-family: Arial, Helvetica, sans-serif;
}
.auto-style4 {
    text-align: left;
}
</style>
<script type="text/javascript">
<!--
function FP_preloadImgs() {//v1.0
 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}

function FP_swapImg() {//v1.0
 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
 n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 elm.$src=elm.src; elm.src=args[n+1]; } }
}

function FP_getObjectByID(id,o) {//v1.0
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
 return null;
}
// -->
</script>
<link href="Gallery%20Styles.css" rel="stylesheet" type="text/css" />
<link href="Sperrin%20Soul%20Gallery%20styles.css" rel="stylesheet" type="text/css" />
</head>

<body onload="FP_preloadImgs(/*url*/'Media/Images/Button_Images/button75.jpg',/*url*/'Media/Images/Button_Images/button76.jpg',/*url*/'Media/Images/Button_Images/button78.jpg',/*url*/'Media/Images/Button_Images/button79.jpg',/*url*/'Media/Images/Button_Images/button7B.jpg',/*url*/'Media/Images/Button_Images/button7C.jpg',/*url*/'Media/Images/Button_Images/button7E.jpg',/*url*/'Media/Images/Button_Images/button7F.jpg',/*url*/'Media/Images/Button_Images/button81.jpg',/*url*/'Media/Images/Button_Images/button82.jpg',/*url*/'Media/Images/Button_Images/button84.jpg',/*url*/'Media/Images/Button_Images/button85.jpg')" style="height: 193px">

<table style="width: 100%">
    <tr>
        <td style="width: 553px">
        <img alt="" height="118" src="Media/Images/Sperrin%20Soul%20Logo.jpg" style="float: right" width="285" /></td>
        <td class="auto-style1"><strong><em>...discover more</em></strong></td>
    </tr>
    <tr>
        <td class="auto-style2" colspan="2">
        <img id="img1" alt="Page 1" height="20" onmousedown="FP_swapImg(1,0,/*id*/'img1',/*url*/'Media/Images/Button_Images/button76.jpg')" onmouseout="FP_swapImg(0,0,/*id*/'img1',/*url*/'Media/Images/Button_Images/button74.jpg')" onmouseover="FP_swapImg(1,0,/*id*/'img1',/*url*/'Media/Images/Button_Images/button75.jpg')" onmouseup="FP_swapImg(0,0,/*id*/'img1',/*url*/'Media/Images/Button_Images/button75.jpg')" src="Media/Images/Button_Images/button74.jpg" style="border: 0" width="100" /><!-- MSComment="ibutton" fp-style="fp-btn: Border Bottom 1" fp-title="Page 1" -->&nbsp;
        <img id="img2" alt="Page 2" height="20" onmousedown="FP_swapImg(1,0,/*id*/'img2',/*url*/'Media/Images/Button_Images/button79.jpg')" onmouseout="FP_swapImg(0,0,/*id*/'img2',/*url*/'Media/Images/Button_Images/button77.jpg')" onmouseover="FP_swapImg(1,0,/*id*/'img2',/*url*/'Media/Images/Button_Images/button78.jpg')" onmouseup="FP_swapImg(0,0,/*id*/'img2',/*url*/'Media/Images/Button_Images/button78.jpg')" src="Media/Images/Button_Images/button77.jpg" style="border: 0" width="100" /><!-- MSComment="ibutton" fp-style="fp-btn: Border Bottom 1" fp-title="Page 2" -->&nbsp;
        <img id="img3" alt="Page 3" height="20" onmousedown="FP_swapImg(1,0,/*id*/'img3',/*url*/'Media/Images/Button_Images/button7C.jpg')" onmouseout="FP_swapImg(0,0,/*id*/'img3',/*url*/'Media/Images/Button_Images/button7A.jpg')" onmouseover="FP_swapImg(1,0,/*id*/'img3',/*url*/'Media/Images/Button_Images/button7B.jpg')" onmouseup="FP_swapImg(0,0,/*id*/'img3',/*url*/'Media/Images/Button_Images/button7B.jpg')" src="Media/Images/Button_Images/button7A.jpg" style="border: 0" width="100" /><!-- MSComment="ibutton" fp-style="fp-btn: Border Bottom 1" fp-title="Page 3" -->&nbsp;
        <img id="img4" alt="Page 4" height="20" onmousedown="FP_swapImg(1,0,/*id*/'img4',/*url*/'Media/Images/Button_Images/button7F.jpg')" onmouseout="FP_swapImg(0,0,/*id*/'img4',/*url*/'Media/Images/Button_Images/button7D.jpg')" onmouseover="FP_swapImg(1,0,/*id*/'img4',/*url*/'Media/Images/Button_Images/button7E.jpg')" onmouseup="FP_swapImg(0,0,/*id*/'img4',/*url*/'Media/Images/Button_Images/button7E.jpg')" src="Media/Images/Button_Images/button7D.jpg" style="border: 0" width="100" /><!-- MSComment="ibutton" fp-style="fp-btn: Border Bottom 1" fp-title="Page 4" -->&nbsp;
        <img id="img5" alt="Page 5" height="20" onmousedown="FP_swapImg(1,0,/*id*/'img5',/*url*/'Media/Images/Button_Images/button82.jpg')" onmouseout="FP_swapImg(0,0,/*id*/'img5',/*url*/'Media/Images/Button_Images/button80.jpg')" onmouseover="FP_swapImg(1,0,/*id*/'img5',/*url*/'Media/Images/Button_Images/button81.jpg')" onmouseup="FP_swapImg(0,0,/*id*/'img5',/*url*/'Media/Images/Button_Images/button81.jpg')" src="Media/Images/Button_Images/button80.jpg" style="border: 0" width="100" /><!-- MSComment="ibutton" fp-style="fp-btn: Border Bottom 1" fp-title="Page 5" -->&nbsp;
        <img id="img6" alt="Page 6" height="20" onmousedown="FP_swapImg(1,0,/*id*/'img6',/*url*/'Media/Images/Button_Images/button85.jpg')" onmouseout="FP_swapImg(0,0,/*id*/'img6',/*url*/'Media/Images/Button_Images/button83.jpg')" onmouseover="FP_swapImg(1,0,/*id*/'img6',/*url*/'Media/Images/Button_Images/button84.jpg')" onmouseup="FP_swapImg(0,0,/*id*/'img6',/*url*/'Media/Images/Button_Images/button84.jpg')" src="Media/Images/Button_Images/button83.jpg" style="border: 0" width="100" /><!-- MSComment="ibutton" fp-style="fp-btn: Border Bottom 1" fp-title="Page 6" --></td>
    </tr>
    <tr>
        <td colspan="2">
        <p class="auto-style3"><strong><em><!-- #BeginEditable "Page_Title" -->
        (Page_Title)<!-- #EndEditable --></em></strong></p>
        </td>
    </tr>
</table>
<br />


<div style="height: 655px">

<div id="div_container" class="auto-style4" style="font-family: Arial, Helvetica, sans-serif; margin-top: 1cm; margin-right: auto; margin-left: auto; padding: 10px; width: 1200px; text-align: center;">
    <!-- #BeginEditable "Box_left" -->
    <div id="div_left" style="font-family: Arial, Helvetica, sans-serif; font-size: medium; border: medium solid #C0C0C0; border-radius: 8px; padding: 8px; width: 700px; display: inline-block; vertical-align: top;">
        <h1>Make an online Booking!</h1>
        <h1><br />

        </h1>
        <form id="form1" runat="server">
            <div class="auto-style4">
                <br />
                To make a new booking please click on '<strong>New</strong>' 
                below:<br />
            </div>
            <div class="auto-style4">
                <asp:FormView id="FormView1" runat="server" AllowPaging="True" BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2" DataKeyNames="BookingID" DataSourceID="AccessDataSource1" Font-Bold="False" ForeColor="Black" GridLines="Both">
                    <EditItemTemplate>
                        BookingID:
                        <asp:Label id="BookingIDLabel1" runat="server" Text='<%# Eval("BookingID") %>' />
                        <br />
                        CustomerName:
                        <asp:TextBox id="CustomerNameTextBox" runat="server" Text='<%# Bind("CustomerName") %>' />
                        <br />
                        BookingDate:
                        <asp:TextBox id="BookingDateTextBox" runat="server" Text='<%# Bind("BookingDate") %>' />
                        <br />
                        EventType:
                        <asp:TextBox id="EventTypeTextBox" runat="server" Text='<%# Bind("EventType") %>' />
                        <br />
                        NumInGroup:
                        <asp:TextBox id="NumInGroupTextBox" runat="server" Text='<%# Bind("NumInGroup") %>' />
                        <br />
                        <asp:LinkButton id="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
                        &nbsp;<asp:LinkButton id="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                    </EditItemTemplate>
                    <EditRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                    <FooterStyle BackColor="#CCCCCC" />
                    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                    <InsertItemTemplate>
                        CustomerName:
                        <asp:TextBox id="CustomerNameTextBox0" runat="server" Text='<%# Bind("CustomerName") %>' />
                        <br />
                        BookingDate:
                        <asp:TextBox id="BookingDateTextBox0" runat="server" Text='<%# Bind("BookingDate") %>' />
                        <br />
                        EventType:
                        <asp:TextBox id="EventTypeTextBox0" runat="server" Text='<%# Bind("EventType") %>' />
                        <br />
                        NumInGroup:
                        <asp:TextBox id="NumInGroupTextBox0" runat="server" Text='<%# Bind("NumInGroup") %>' />
                        <br />
                        <asp:LinkButton id="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
                        &nbsp;<asp:LinkButton id="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                    </InsertItemTemplate>
                    <ItemTemplate>
                        BookingID:
                        <asp:Label id="BookingIDLabel" runat="server" Text='<%# Eval("BookingID") %>' />
                        <br />
                        CustomerName:
                        <asp:Label id="CustomerNameLabel" runat="server" Text='<%# Bind("CustomerName") %>' />
                        <br />
                        BookingDate:
                        <asp:Label id="BookingDateLabel" runat="server" Text='<%# Bind("BookingDate") %>' />
                        <br />
                        EventType:
                        <asp:Label id="EventTypeLabel" runat="server" Text='<%# Bind("EventType") %>' />
                        <br />
                        NumInGroup:
                        <asp:Label id="NumInGroupLabel" runat="server" Text='<%# Bind("NumInGroup") %>' />
                        <br />
                        <asp:LinkButton id="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />
                        &nbsp;<asp:LinkButton id="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" />
                        &nbsp;<asp:LinkButton id="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New" />
                    </ItemTemplate>
                    <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
                    <RowStyle BackColor="White" />
                </asp:FormView>
            </div>
            <asp:AccessDataSource id="AccessDataSource1" runat="server" DataFile="BookingDB.mdb" DeleteCommand="DELETE FROM [tbl_Booking] WHERE [BookingID] = ?" InsertCommand="INSERT INTO [tbl_Booking] ([CustomerName], [BookingDate], [EventType], [NumInGroup]) VALUES (?, ?, ?, ?)" SelectCommand="SELECT [BookingID], [CustomerName], [BookingDate], [EventType], [NumInGroup] FROM [tbl_Booking]" UpdateCommand="UPDATE [tbl_Booking] SET [CustomerName] = ?, [BookingDate] = ?, [EventType] = ?, [NumInGroup] = ? WHERE [BookingID] = ?">
                <DeleteParameters>
                    <asp:Parameter Name="BookingID" Type="Int32" />
                </DeleteParameters>
                <InsertParameters>
                    <asp:Parameter Name="CustomerName" Type="String" />
                    <asp:Parameter Name="BookingDate" Type="DateTime" />
                    <asp:Parameter Name="EventType" Type="String" />
                    <asp:Parameter Name="NumInGroup" Type="Int16" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="CustomerName" Type="String" />
                    <asp:Parameter Name="BookingDate" Type="DateTime" />
                    <asp:Parameter Name="EventType" Type="String" />
                    <asp:Parameter Name="NumInGroup" Type="Int16" />
                    <asp:Parameter Name="BookingID" Type="Int32" />
                </UpdateParameters>
            </asp:AccessDataSource>
            <div class="auto-style4">
                <br />
                Please view all our current bookings below:<asp:GridView id="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2" DataKeyNames="BookingID" DataSourceID="AccessDataSource2" ForeColor="Black">
                    <Columns>
                        <asp:BoundField DataField="BookingID" HeaderText="BookingID" InsertVisible="False" ReadOnly="True" SortExpression="BookingID">
                        </asp:BoundField>
                        <asp:BoundField DataField="CustomerName" HeaderText="CustomerName" SortExpression="CustomerName">
                        </asp:BoundField>
                        <asp:BoundField DataField="BookingDate" HeaderText="BookingDate" SortExpression="BookingDate">
                        </asp:BoundField>
                        <asp:BoundField DataField="StartTime" HeaderText="StartTime" SortExpression="StartTime">
                        </asp:BoundField>
                        <asp:BoundField DataField="EventType" HeaderText="EventType" SortExpression="EventType">
                        </asp:BoundField>
                        <asp:BoundField DataField="NumInGroup" HeaderText="NumInGroup" SortExpression="NumInGroup">
                        </asp:BoundField>
                    </Columns>
                    <FooterStyle BackColor="#CCCCCC" />
                    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
                    <RowStyle BackColor="White" />
                    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                    <SortedAscendingCellStyle BackColor="#F1F1F1" />
                    <SortedAscendingHeaderStyle BackColor="#808080" />
                    <SortedDescendingCellStyle BackColor="#CAC9C9" />
                    <SortedDescendingHeaderStyle BackColor="#383838" />
                </asp:GridView>
                <br />
                <asp:AccessDataSource id="AccessDataSource2" runat="server" DataFile="BookingDB.mdb" SelectCommand="SELECT [BookingID], [CustomerName], [BookingDate], [StartTime], [EventType], [NumInGroup] FROM [tbl_Booking]">
                </asp:AccessDataSource>
                <br />
                <br />
                <br />
            </div>
        </form>

    </div>
    <!-- #EndEditable -->
<!-- #BeginEditable "Box_Right" -->
    <div id="div_right" style="font-family: Arial, Helvetica, sans-serif; font-size: medium; border: medium solid #66CCFF; border-radius: 8px; padding: 8px; width: 300px; display: inline-block; text-align: center;">

<div class="VerticalPictureplaceholder">
<img alt="" src="Media/Images/Online_Booking.jpg" />
</div>
<div class="Description">make on instant online booking!</div>

<div class="VerticalPictureplaceholder">
<img alt="" src="Media/Images/Book-Online.jpg" />
</div>
<div class="Description">Enjoy walking the mountains</div>

<div class="VerticalPictureplaceholder">
<img alt="" src="Media/Images/phone%20call.jpg" />
</div>
<div class="Description">A natural wonder</div>
    </div>
<!-- #EndEditable -->
</div>
<div id="div_footer" class="auto-style2" style="font-family: Arial, Helvetica, sans-serif; margin-left: auto; margin-right: auto">
    <em>updated on 19/12/2019<br />
    contact webmaster@gmail.com</em></div>
</div>


</body>

<!-- #EndTemplate -->

</html>

3 个答案:

答案 0 :(得分:1)

似乎您是从某个地方复制了FormView代码并将其粘贴到.aspx文件中的吗?

如果是这样,一个独立的aspx页面应如下所示。这会限制您可以使用的代码,因为没有代码隐藏文件可以处理更复杂的操作。

<%@ Page Language="C#" %>

<!DOCTYPE html>
<html>
<head>
    <title>Demo</title>
</head>
<body>

    <form runat="server" id="form1">

        <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1">
            <ItemTemplate>

                <asp:Label ID="Label1" runat="server" Text='<%# Eval("column1") %>' /> 

                 or 

                 <%# Eval("column1") %>

            </ItemTemplate>
        </asp:FormView>

        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="MyConnectionString" SelectCommand="select * from mytable" />

    </form>

</body>
</html>

有关更多信息,请参见这些链接。但是,如果您在aspx页面上执行更多操作,我建议您在Visual Studio中创建一个项目,然后从那里开始工作。

http://www.beansoftware.com/ASP.NET-Tutorials/FormView-Control.aspx

https://docs.microsoft.com/en-us/aspnet/web-forms/overview/data-access/custom-formatting/using-the-formview-s-templates-cs

https://www.c-sharpcorner.com/UploadFile/abhikumarvatsa/formview-control-in-Asp-Net-part-12/

https://www.aspsnippets.com/Articles/GridView-FormView-Master-Detail-example-in-ASPNet.aspx

https://www.tutorialride.com/asp-net/detailsview-and-formview-controls-in-asp-net.htm

答案 1 :(得分:0)

在Microsoft Expression Web 4中,在“站点”>“站点设置”下,有一个用于使用Microsoft Expression Development Server预览网页的选项。它设置为选项:

  

仅适用于PHP和ASP.NET网页

要解决此问题,我必须选择第二个选项:

  

对于所有网页。

这实际上意味着我正在从LocalHost预览我的所有网页(HTML和ASPX页面)。

答案 2 :(得分:0)

您需要在Asp页面顶部具有页面目录。

<%@ Page Title="YourTitle" Language="C#" AutoEventWireup="false" CodeBehind="YourCodeBehind.aspx.cs" Inherits="YourCodeBehindNamspace" %>

还请检查您的Web服务器是否配置为使用.Net框架?听起来好像ASP.Net ISAPI筛选器没有启动并翻译页面。

相关问题