2014-06-11 3 views
3

웹 응용 프로그램을 처음 사용했습니다. 현재 Visual Studio 2013을 사용하고 있으며 웹 응용 프로그램을 만들었습니다. 나는 직원들이 작성한 양식을 가지고 싶습니다. 양식을 제출하면 데이터베이스에서 추가, 변경 또는 삭제됩니다. 연구에서 나는 원래 웹 양식을 만들려고했다. 이것은 내가 마스터 페이지에서 만든 서식을 유지하는 것을 허용하지 않았고, 마스터 페이지에 연결하려고 시도했을 때 <form> 때문에 허용하지 않았습니다. 그럼 마스터 페이지가있는 웹 양식을 만들었습니다. 이렇게하면 마스터 페이지에서 서식을 유지할 수 있지만 이제는 <form>을 사용하여 양식을 만들 수 없습니다. 그래서 내 질문은 제출하고 여전히 마스터 페이지에서 서식을 유지할 양식을 어떻게 만듭니 까?웹 페이지와 웹 양식의 차이점은 마스터 페이지입니까?

마스터 페이지 :

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="WebApplication1.WebForm3" %> 

<!DOCTYPE html> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <div id="Column1" style="height:355px;width:250px;float:left;"> 
     First Name: <input type="text" name="FirstName" /> 
     First Name: <input type="text" name="FirstName" /> 
     First Name: <input type="text" name="FirstName" /> 
     First Name: <input type="text" name="FirstName" /> 
     First Name: <input type="text" name="FirstName" /> 
     First Name: <input type="text" name="FirstName" /> 
     First Name: <input type="text" name="FirstName" /> 
     First Name: <input type="text" name="FirstName" /> 
     First Name:&nbsp; <input type="text" name="FirstName1" size="20" /> 
     <select id="Select1" name="D1"> 
      <option>This</option> 
      <option>That</option> 
      <option>The other thing</option> 
     </select></div> 
    <div id="Column2" style="height:355px;width:250px;float:left;"> 
     First Name: <input type="text" name="FirstName2" size="20" /> 
     First Name: <input type="text" name="FirstName3" size="20" /> 
     First Name: <input type="text" name="FirstName4" size="20" /> 
     First Name: <input type="text" name="FirstName5" size="20" /> 
     First Name: <input type="text" name="FirstName6" size="20" /> 
     First Name: <input type="text" name="FirstName7" size="20" /> 
     First Name: <input type="text" name="FirstName8" size="20" /> 
     First Name: <input type="text" name="FirstName9" size="20" /> 
     First Name: <input type="text" name="FirstName10" size="20" /> 
    </div> 
    </body> 
</html> 

내가 형태로 내 웹 양식의 신체 내에서 모든 것을하고 싶은

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="WebApplication1.SiteMaster" %> 

<!DOCTYPE html> 

<html lang="en"> 
<head runat="server"> 
    <meta charset="utf-8" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /> 
    <title><%: Page.Title %> Employee Information</title> 

    <asp:PlaceHolder runat="server"> 
     <%: Scripts.Render("~/bundles/modernizr") %> 
    </asp:PlaceHolder> 
    <webopt:bundlereference runat="server" path="~/Content/css" /> 
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" /> 

</head> 
<body> 
    <form runat="server"> 
     <asp:ScriptManager runat="server"> 
      <Scripts> 
       <%--To learn more about bundling scripts in ScriptManager see http://go.microsoft.com/fwlink/?LinkID=301884 --%> 
       <%--Framework Scripts--%> 
       <asp:ScriptReference Name="MsAjaxBundle" /> 
       <asp:ScriptReference Name="jquery" /> 
       <asp:ScriptReference Name="bootstrap" /> 
       <asp:ScriptReference Name="respond" /> 
       <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" /> 
       <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" /> 
       <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" /> 
       <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" /> 
       <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" /> 
       <asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" /> 
       <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" /> 
       <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" /> 
       <asp:ScriptReference Name="WebFormsBundle" /> 
       <%--Site Scripts--%> 
      </Scripts> 
     </asp:ScriptManager> 

     <div class="navbar navbar-inverse navbar-fixed-top"> 
      <div class="container"> 
       <div class="navbar-header"> 
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> 
         <span class="icon-bar"></span> 
         <span class="icon-bar"></span> 
         <span class="icon-bar"></span> 
        </button> 
        <!--<a class="navbar-brand" runat="server" href="~/">Employee Information</a>--> 
       </div> 
       <div class="navbar-collapse collapse"> 
        <ul class="nav navbar-nav"> 
         <li><a runat="server" href="~/HomePage">Home</a></li> 
         <!--<li><a runat="server" href="~/About">About</a></li>--> 
         <li><a runat="server" href="~/EmployeeInput">Add Employee</a></li> 
         <li><a runat="server" href="~/EditEmployee">Edit Information</a></li> 
         <li><a runat="server" href="~/Terminate">Terminate Employee</a></li> 
        </ul> 
        <asp:LoginView runat="server" ViewStateMode="Disabled"> 
         <AnonymousTemplate> 
          <ul class="nav navbar-nav navbar-right"> 
           <li><a runat="server" href="~/Account/Register">Register</a></li> 
           <li><a runat="server" href="~/Account/Login">Log in</a></li> 
          </ul> 
         </AnonymousTemplate> 
         <LoggedInTemplate> 
          <ul class="nav navbar-nav navbar-right"> 
           <li><a runat="server" href="~/Account/Manage" title="Manage your account">Hello, <%: Context.User.Identity.GetUserName() %> !</a></li> 
           <li> 
            <asp:LoginStatus runat="server" LogoutAction="Redirect" LogoutText="Log off" LogoutPageUrl="~/" OnLoggingOut="Unnamed_LoggingOut" /> 
           </li> 
          </ul> 
         </LoggedInTemplate> 
        </asp:LoginView> 
       </div> 
      </div> 
     </div> 
     <div class="container body-content"> 
      <asp:ContentPlaceHolder ID="MainContent" runat="server"> 
      </asp:ContentPlaceHolder> 
      <hr /> 
      <footer> 
       <p>&copy; <%: DateTime.Now.Year %> </p> 
      </footer> 
     </div> 
    </form> 
</body> 
</html> 

웹 양식.

+0

masterpage 및 webforms 페이지를 표시 할 수 있습니까? 일반적으로 폼 태그가 '

'와 같은지 확인해야합니다. [ASP.net 양식] (http://www.w3schools.com/aspnet/aspnet_forms.asp)에 대한 추가 정보 – Mivaweb

답변

4

복합 페이지 (페이지 + 마스터 페이지)에 runat="server" 속성이있는 양식을 하나만 가질 수 있습니다.

해결 방법은 양식을 마스터 페이지에 넣고 콘텐츠 위치 홀더를 양식 안에 넣는 것입니다. 페이지 자체는 콘텐츠를 가지고 내부에 마크 업을 선언 할 필요가 없습니다. 페이지가 실행되면 페이지 및 마스터 페이지의 마크 업이 클라이언트로 전송되는 단일 HTML 파일로 결합됩니다.

예 마스터 페이지 :

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="Site" %> 

<!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"> 
    <title>Working with Data Tutorials</title> 
    <link href="Styles.css" rel="stylesheet" type="text/css" /> 
</head> 
<body> 
    <div id="wrapper"> 

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

      <div id="header"> 
       <span class="title">Working with Data Tutorials</span> 
       <span class="breadcrumb">TODO: Breadcrumb will go here...</span> 
      </div> 

      <div id="content"> 
       <asp:contentplaceholder id="MainContent" runat="server"> 
        <!-- Page-specific content will go here... --> 
       </asp:contentplaceholder> 
      </div> 

      <div id="navigation"> 
       TODO: Menu will go here... 
      </div> 
     </form> 
    </div> 
</body> 
</html> 

예 컨텐츠 페이지 : 페이지에 대한 뒤에 코드 (.cs 파일)에

<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Home" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server"> 
    <h1>Welcome to the Working with Data Tutorial Site</h1> 

    <p>This site is being built as part of a set of tutorials that illustrate some of the new data access and databinding features in ASP.NET 2.0 and Visual Web Developer.</p> 

<asp:TextBox runat="server" id="TextBox1" /><br /> 
<asp:TextBox runat="server" id="TextBox2" /><br /> 
<asp:Button runat="server" id="Btn1" OnClick="Btn1_Click" Text="Click to submit!" /> 

     </asp:Content> 

, 당신은 같은 텍스트 상자에서 값을 읽을 것 이 :

protected void Btn1_Click(object sender, EventArgs e) 
{ 
    string sometext=TextBox1.Text; 
    string somemoretext=TextBox2.Text; 
} 

예제 from MSDN.

+0

좋아,이 예제처럼 설정된 콘텐츠 페이지가 있습니다. 그래도 어떻게 양식을 만들 수 있습니까? 콘텐츠 페이지는 '

'을 허용하지 않으므로 제출 버튼에 대한 조치 문을 입력 할 수 없습니다. action 문은 마스터 페이지에도 있습니까? 그렇다면 나를 위해 어디에서 보여줄 수 있습니까? –

+0

@ user3730892 양식 작업 진술이란 무엇입니까? 포스트 백을 발생시키는 버튼을 의미합니까? – mason

+0

내가 말했듯이 나는 이것에 정말로 새로운 것이다. 지금까지 읽은 것부터 입력 상자 집합에서 SQL Server와 같은 입력 상자에 아무것도 게시하고 싶다면 '<입력 제출> ' –

관련 문제