1

I tried the following code to the Webform.aspx page:

 <asp:Button ID="btnShowAssignLecturer" runat="server" 
        onclick="btnShowAssignLecturer_Click" Text="Assign Lecturer To Room" />

It says: System.Web.HttpException: Control 'ctl00_head_btnShowAssignLecturer' of type 'Button' must be placed inside a form tag with runat=server.

When I do that, I get another error. Not quite sure what to do.

Master page code:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MasterPage.master.cs" Inherits="AllsWellHospital.Front_End.MasterPage" %>

<!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">
<head runat="server">
    <h1>All Wells Hospital</h1>
      <p>
      <asp:Label ID="DateDisplay" runat="server"></asp:Label>
      </p>
    <asp:ContentPlaceHolder ID="head" runat="server"></asp:ContentPlaceHolder>   
    <link id="Link1" href="/Styles/StyleSheet2.css" runat="server" rel="stylesheet" type="text/css"/>
    <style>
    body
    {
     background-color:#d0e4fe;   
    }
    </style>

</head>
<body>
    <form id="form1" runat="server">    
     <div id="topContent">
     <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
             <Items>
      <asp:MenuItem NavigateUrl="WebForm1.aspx" Text="Web form.aspx"  Value="Upload SP10"></asp:MenuItem>
             </Items>
            </asp:Menu>
    </div>




    </form>
</body>
</html>

Webform.aspx code:

<%@ Page Title="" Language="C#" MasterPageFile="~/Front_End/MasterPage.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="AllsWellHospital.Front_End.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

 <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="Medium" 
        Text="Course Report"></asp:Label>

         <asp:Button ID="btnShowAssignLecturer" runat="server" 
        onclick="btnShowAssignLecturer_Click" Text="Assign Lecturer To Room" />

</asp:Content>
4

2 に答える 2

1

ボタンはフォームタグ内にある必要がありますが、現在はそうではありません。フォームのヘッド部分にボタンを配置しますか? メイン コンテンツ用に別のコンテンツ エリアを追加してみませんか。次のようにしてみてください。

マスター ページ:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MasterPage.master.cs" Inherits="AllsWellHospital.Front_End.MasterPage" %>
<!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">
<head id="Head1" runat="server">

<h1>All Wells Hospital</h1>
  <p>
  <asp:Label ID="DateDisplay" runat="server"></asp:Label>
  </p>
<asp:ContentPlaceHolder ID="head" runat="server"></asp:ContentPlaceHolder>   
<link id="Link1" href="/Styles/StyleSheet2.css" runat="server" rel="stylesheet" type="text/css"/>
<style>
body
{
 background-color:#d0e4fe;   
}
</style>

</head>
<body>
<form id="form1" runat="server">    
 <div id="topContent">
 <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
         <Items>
  <asp:MenuItem NavigateUrl="WebForm1.aspx" Text="Web form.aspx"  Value="Upload SP10"></asp:MenuItem>
         </Items>
        </asp:Menu>
</div>
    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"></asp:ContentPlaceHolder>



</form>

あなたのaspx:

<%@ Page Title="" Language="C#" MasterPageFile="~/Front_End/MasterPage.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="AllsWellHospital.Front_End.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="Medium" 
    Text="Course Report"></asp:Label>


</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  <asp:Button ID="Button1" runat="server" 
    onclick="btnShowAssignLecturer_Click" Text="Assign Lecturer To Room" />
</asp:Content>
于 2013-06-18T04:06:35.903 に答える
0

<form>ポストが実際に ASP パイプラインで何かを実行するには、サーバー マネージド タグ内にボタンを配置する必要があります。

ただし、コンテンツ プレース ホルダーは、無効なマスター ページのタグContent1内にあります。このコンテンツが要素内に存在しないようにマスター ページを再考し、フォームを囲む必要があります。<head><form><head><form runat='server'>

<header>通常の要素とは明らかに異なるHTML 5 要素を使用するつもりだったのかもしれません<head>

于 2013-06-18T03:58:37.457 に答える