Web表格不能正常工作

时间:2013-11-03 16:08:05

标签: asp.net webforms

我是ASP.NET新手,似乎搞砸了一个基于Master的Web Form页面。 似乎我混合了一些无效的HTML代码,但无法弄清楚原因。

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Clips.aspx.cs" Inherits="Clip.Clips" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">

        <asp:EntityDataSource ID="entityDataSource" runat="server" ConnectionString="name=ClipEnt" DefaultContainerName="ClipEnt" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="Clips" EntityTypeFilter="Clip" OnSelecting="EntityDataSource_Selecting">
        </asp:EntityDataSource>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="entityDataSource">
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" />
            </Columns>
        </asp:GridView>

            <div>
            <h1>Sending Email</h1>
        <table>
            <tr>
                <td>From:</td>
                <td>
                    <asp:TextBox ID="txtFrom" runat="server" Width="250px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>From EMail:</td>
                <td>
                    <asp:TextBox ID="txtFromEmail" runat="server" Width="250px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>To:</td>
                <td>
                    <asp:TextBox ID="txtTo" runat="server" Width="250px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>To Email:</td>
                <td>
                    <asp:TextBox ID="txtToEmail" runat="server" Width="250px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Subject:</td>
                <td>
                    <asp:TextBox ID="txtSubject" runat="server" Width="250px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Message:</td>
                <td>
                    <asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine" Height="138px" 
                        Width="467px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td colspan="2" align="right">
                    <asp:Button ID="btnSend" runat="server" Text="Send Email" 
                        onclick="btnSend_Click" />
                </td>
            </tr>
        </table>
        <asp:Label ID="Label1" runat="server" ForeColor="Blue" />
    </div>
    </form>
</body>
</html>

</asp:Content>

2 个答案:

答案 0 :(得分:0)

在主页中你有这样的东西:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

您只需要在内容页面中使用此剥离标记。请注意,我已从内容页面中删除了DOCTYPE<html><head><body><form>标记 - 它们将从 Site.Master呈现母版页。

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Clips.aspx.cs" Inherits="Clip.Clips" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <asp:EntityDataSource ID="entityDataSource" runat="server" ConnectionString="name=ClipEnt" DefaultContainerName="ClipEnt" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="Clips" EntityTypeFilter="Clip" OnSelecting="EntityDataSource_Selecting">
    </asp:EntityDataSource>
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="entityDataSource">
        <Columns>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" />
        </Columns>
    </asp:GridView>

    <div>
        <h1>Sending Email</h1>
        <table>
            <tr>
                <td>From:</td>
                <td>
                    <asp:TextBox ID="txtFrom" runat="server" Width="250px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>From EMail:</td>
                <td>
                    <asp:TextBox ID="txtFromEmail" runat="server" Width="250px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>To:</td>
                <td>
                    <asp:TextBox ID="txtTo" runat="server" Width="250px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>To Email:</td>
                <td>
                    <asp:TextBox ID="txtToEmail" runat="server" Width="250px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Subject:</td>
                <td>
                    <asp:TextBox ID="txtSubject" runat="server" Width="250px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>Message:</td>
                <td>
                    <asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine" Height="138px"
                        Width="467px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td colspan="2" align="right">
                    <asp:Button ID="btnSend" runat="server" Text="Send Email"
                        OnClick="btnSend_Click" />
                </td>
            </tr>
        </table>
        <asp:Label ID="Label1" runat="server" ForeColor="Blue" />
    </div>
</asp:Content>

答案 1 :(得分:0)

开发asp.net网站时要记住一些要点 -

  1. asp.net网络表单只能包含一个带有form属性的runat='server'标记。因此,当Web表单继承自母版页时,它会从母版页继承form标记。因此,无需单独向网络表单添加form标记。
  2. 页面的公共部分应放在母版页中,其中更改的部分应放在继承母版页的Web表单中。站点页眉和页脚对每个页面都是静态的。所以它们应该放在母版页上。网站的内容在不同页面之间变化。所以它们应该放在继承母版页的Web表单上。
  3. 公共资源的链接,即网站样式表和javascript文件也应该在母版页中放置一次。继承母版页的Web表单将自动继承它们。
  4. 通过以下一些操作,您可以轻松地使用母版页开发Web表单。