链接aspx.cs文件和母版页

时间:2013-04-09 16:32:25

标签: master-pages

我已经在这项任务中苦苦挣扎了很长一段时间。我需要使用母版页并将其链接到两个ASPX页面。任何帮助或建议都会非常有帮助。我的问题是我通过这个母版页运行两个程序,我无法使它们正常工作。当我单击提交按钮时,它不会发布任何结果,这些结果都是没有母版页的。谢谢!

这是我的母版页代码:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="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">
    <title></title>
    <asp:ContentPlaceHolder id="HeadContent" runat="server">
    </asp:ContentPlaceHolder>
    <link href="Math.css" rel="Stylesheet" type="text/css" /> 
</head>
<body>
    <form id="form1" runat="server">
    <div id="divWrapper">
        <div id="mainContent" > <!-- This div will contain the main content of the page, unique -->
        <asp:ContentPlaceHolder id="contentMain" runat="server">

        </asp:ContentPlaceHolder>
        </div>
        <div id="divLeftContent" > <!-- Contains left content, buttons -->
            <div id="LnkMenuIndividualButtons">

                <!-- #include file="leftcontent.htm" -->
            </div>
        </div>
    </div>
    </form>
</body>
</html>

Heres triangles.aspx

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true"
    CodeFile="Triangles.aspx.cs" Inherits="_Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
 <% trianglePossible();
    primeNumbers(); %>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="contentMain">

</asp:Content>

这是Triangles.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public void trianglePossible()
    {
        try
        {
            decimal length1 = decimal.Parse(Request.Form["Text1"]);
            decimal length2 = decimal.Parse(Request.Form["Text2"]);
            decimal length3 = decimal.Parse(Request.Form["Text3"]);
            if ((length1 + length2 > length3) && (length2 + length3 > length1) && (length1 + length3 > length2))
            {
                Response.Write(" This triangle is possible. ");
            }
            else
            {
                Response.Write(" This triangle is not possible. ");
            }
        }
        catch
        {
            Response.Write(" Go back and fix error, must contain all numerics only. ");
        }


    }

   public void primeNumbers()
       {
        int primeNumber1 = int.Parse(Request.Form["Text4"]);

        bool prime = true;
        for (int i = 2; i < primeNumber1 - 1; i++)
        {


            if (primeNumber1 % i == 0)
            {
                prime = false;
            }

        }
        if (prime == true)
        {
            Response.Write(" This is a prime number! ");

        }
        else
        {
            Response.Write(" This is not a prime number! ");
        }
        if (primeNumber1 > 999 || primeNumber1 < 0)
        {
            Response.Write(" Please return and enter a number between the values of 0 and 999. ");
        }
    }

}

这是TriangleLength.aspx

<%@ Page Language="C#" AutoEventWireup="true"  MasterPageFile="~/MasterPage.master" CodeFile="TriangleLength.aspx.cs" Inherits="_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="contentMain" Runat="Server">

    <form action="Triangles.aspx" method="post">
    <p>&nbsp;&nbsp;&nbsp;&nbsp;Triangle Lengths</p>
    <p><input name="Text1" id="Text1" type="text" /></p>
    <p><input name="Text2" id="Text2" type="text" /></p>
    <p><input name="Text3" id="Text3" type="text" /></p>
    <input type="submit" value="Submit" />
    </form>   

</asp:Content>

最后,这里是Prime NUmbers.aspx

<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/MasterPage.master" CodeFile="Triangles.aspx.cs" Inherits="_Default" %>


<asp:Content ID="Content1" ContentPlaceHolderID="contentMain" Runat="Server">

<form action="Triangles.aspx" method="post">
  <p>Prime Numbers</p>
    <p><input name="Text4" id="Text4" type="text" /></p>
    <input type="submit" value="Submit" />
     </form>

</asp:Content>

1 个答案:

答案 0 :(得分:0)

尝试从您的主页或.aspx页面中删除<form>