aspx页面无法与aspx.cs文件

时间:2017-04-05 14:01:16

标签: c# asp.net

所以基本上我有一个名为Lab4.aspx的网页表单但每次按下按钮时,它总是指向脚本runat =“server”而不是aspx.cs,当我更改它时按钮也会改回Button_1到BtnSubmit

<script runat="server">

    Protected Sub Button1_Click(sender As Object, e As EventArgs)

    End Sub
</script>

对于aspx.cs,我已经将公共部分类更改为aspx.cs中的公共部分类Lab4:System.Web.UI.Page,并将文件命名为Lab4.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 Lab4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void BtnSubmit_Click(object sender, EventArgs e)

如果能够解决这个谜团会很棒,因为我已经尝试过到处寻找这个解决方案

这是aspx页面上按钮控件的代码

<asp:Button ID="BtnSubmit" runat="server" onclick="Button1_Click" Text="Submit" 
                        Width="85px" />

这是aspx页面的完整代码

<script runat="server">

    Protected Sub Button1_Click(sender As Object, e As EventArgs)

    End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            font-size: xx-large;
            font-family: "Tw Cen MT";
            height: 1161px;
        }
        .style2
        {
            text-decoration: underline;
        }
        .style3
        {
            font-size: x-large;
            background-color: #9933FF;
        }
        .style4
        {
            width: 100%;
        }
        .style5
        {
            width: 243px;
        }
        .style6
        {
            width: 609px;
        }
        .style7
        {
            width: 243px;
            height: 32px;
        }
        .style8
        {
            width: 609px;
            height: 32px;
            background-color: #FFFFFF;
        }
        .style9
        {
            height: 32px;
        }
        .style10
        {
            background-color: #9966FF;
        }
        .style11
        {
            width: 243px;
            height: 31px;
        }
        .style12
        {
            width: 609px;
            height: 31px;
        }
        .style13
        {
            height: 31px;
        }
        .style14
        {
            width: 303px;
            font-size: x-large;
        }
        .style15
        {
            width: 303px;
            height: 41px;
        }
        .style16
        {
            height: 41px;
        }
        .style17
        {
            font-size: x-large;
        }
        .style20
        {
            width: 254px;
        }
        .style21
        {
            width: 254px;
            height: 41px;
        }
        .style22
        {
            width: 243px;
            height: 45px;
        }
        .style23
        {
            width: 609px;
            height: 45px;
        }
        .style24
        {
            height: 45px;
        }
        .style25
        {
            width: 303px;
            font-size: x-large;
            height: 32px;
        }
        .style26
        {
            width: 254px;
            height: 32px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="style1">

        Nasi Tapau O<span class="style2">nline Order&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </span>
        <br />
        <br />
        <span class="style3"><span class="style10">Customer&#39;s Details&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </span>
        <br />
        <table class="style4">
            <tr>
                <td class="style5">
                    Name : 
                </td>
                <td class="style6">
                    <span class="style3">
                    <asp:TextBox ID="TxtName" runat="server" Width="545px"></asp:TextBox>
                    </span>
                </td>
                <td>
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style7">
                </td>
                <td class="style8">
                </td>
                <td class="style9">
                </td>
                <td class="style9">
                </td>
            </tr>
            <tr>
                <td class="style5">
                    Contact Number :</td>
                <td class="style6">
                    <span class="style3">
                    <asp:TextBox ID="TxtContactNo" runat="server" Width="165px"></asp:TextBox>
                    </span>
                </td>
                <td>
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style5">
                    &nbsp;</td>
                <td class="style6">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style5">
                    Email :</td>
                <td class="style6">
                    <span class="style3">
                    <asp:TextBox ID="TxtEmail" runat="server" Width="165px"></asp:TextBox>
                    </span>
                </td>
                <td>
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style7">
                </td>
                <td class="style8">
                </td>
                <td class="style9">
                </td>
                <td class="style9">
                </td>
            </tr>
            <tr>
                <td class="style5">
                    Order Details :</td>
                <td class="style6">
                    &nbsp;</td>
                <td>
                    Quantity :
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style5">
                    &nbsp;</td>
                <td class="style6">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style5">
                    Rice :</td>
                <td class="style6">
                    <asp:RadioButton ID="RBYes" runat="server" Text="Yes" />
&nbsp;<span class="style3"><asp:RadioButton ID="RBNo" runat="server" 
                        style="background-color: #FFFFFF" Text="No" />
                    </span>
                </td>
                <td>
                    <span class="style3">
                    <asp:TextBox ID="TxtQRice" runat="server" Width="165px"></asp:TextBox>
                    </span>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style22">
                </td>
                <td class="style23">
                </td>
                <td class="style24">
                </td>
                <td class="style24">
                </td>
            </tr>
            <tr>
                <td class="style5">
                    Side Dishes :</td>
                <td class="style6">
                    <asp:CheckBox ID="CBChicken" runat="server" style="background-color: #FFFFFF" Text="Chicken Curry - RM4.50" />
                </td>
                <td>
                    <span class="style3">
                    <asp:TextBox ID="TxtQChicken" runat="server" Width="165px"></asp:TextBox>
                    </span>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style7">
                </td>
                <td class="style8">
        <span class="style3">
                    <asp:CheckBox ID="CBMixed" runat="server" OnCheckedChanged="CBMixed_CheckedChanged" style="background-color: #FFFFFF" Text="Mixed Vegetables - RM2.50" />
        </span>
                </td>
                <td class="style9">
                    <span class="style3">
                    <asp:TextBox ID="TxtQMixed" runat="server" Width="165px"></asp:TextBox>
                    </span>
                </td>
                <td class="style9">
                </td>
            </tr>
            <tr>
                <td class="style5">
                    &nbsp;</td>
                <td class="style6">
        <span class="style3">
                    <asp:CheckBox ID="CBGrilled" runat="server" style="background-color: #FFFFFF" Text="Grilled Fish - RM4.00" />
        </span>
                </td>
                <td>
                    <span class="style3">
                    <asp:TextBox ID="TxtQGrilled" runat="server" Width="165px"></asp:TextBox>
                    </span>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style7">
                </td>
                <td class="style8">
        <span class="style3">
                    <asp:CheckBox ID="CBCondiment" runat="server" style="background-color: #FFFFFF" Text="Condiment - RM1.50" />
        </span>
                </td>
                <td class="style9">
                    <span class="style3">
                    <asp:TextBox ID="TxtQCondiment" runat="server" Width="165px"></asp:TextBox>
                    </span>
                </td>
                <td class="style9">
                </td>
            </tr>
            <tr>
                <td class="style5">
                    Beverages :</td>
                <td class="style6">
        <span class="style3">
                    <asp:CheckBox ID="CBMangoJ" runat="server" style="background-color: #FFFFFF" Text="Mango Juice - RM3.00" />
        </span>
                </td>
                <td>
                    <span class="style3">
                    <asp:TextBox ID="TxtMangoJuice" runat="server" Width="165px"></asp:TextBox>
                    </span>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style5">
                    &nbsp;</td>
                <td class="style6">
        <span class="style3">
                    <asp:CheckBox ID="CBCendol" runat="server" style="background-color: #FFFFFF" Text="Cendol - RM3.00" />
        </span>
                </td>
                <td>
                    <span class="style3">
                    <asp:TextBox ID="TxtCendol" runat="server" Width="165px"></asp:TextBox>
                    </span>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style5">
                    &nbsp;</td>
                <td class="style6">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style11">
                    Delivery:</td>
                <td class="style12">
                    <asp:DropDownList ID="DdlDelivery" runat="server">
                        <asp:ListItem Value="0">Self-pickup</asp:ListItem>
                        <asp:ListItem Value="1.50">Request For Delivery</asp:ListItem>
                    </asp:DropDownList>
                </td>
                <td class="style13">
                </td>
                <td class="style13">
                </td>
            </tr>
            <tr>
                <td class="style11">
                    &nbsp;</td>
                <td class="style12">
                    &nbsp;</td>
                <td class="style13">
                    <asp:Button ID="BtnSubmit" runat="server" onclick="Button1_Click" Text="Submit" 
                        Width="85px" />
                </td>
                <td class="style13">
                    &nbsp;</td>
            </tr>
        </table>
        <br />
        <br />
        <asp:Label ID="Label1" runat="server" style="background-color: #9966FF" 
            Text="Thank you for choosing us! Here are you order details :"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <br />
        <br />
        </span>
        <table class="style4">
            <tr>
                <td class="style14">
                    <span class="style17">Name :
                </td>
                <td class="style20">
                    <asp:Label ID="lblName" runat="server" Font-Size="X-Large"></asp:Label>
                    </span>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style14">
                    &nbsp;</td>
                <td class="style20">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style14">
                    Telephone :</td>
                <td class="style20">
                    <span class="style17">
                    <asp:Label ID="LblTel" runat="server"></asp:Label>
                    </span>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style14">
                    &nbsp;</td>
                <td class="style20">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style14">
                    Email :</td>
                <td class="style20">
                    <span class="style17">
                    <asp:Label ID="lblEmail" runat="server"></asp:Label>
                    </span>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style14">
                    &nbsp;</td>
                <td class="style20">
                    &nbsp;</td>
                <td style="font-size: x-large">
                    Quantity :</td>
            </tr>
            <tr>
                <td class="style25">
                    Rice :</td>
                <td class="style26">
                    <span class="style17">
                    <asp:Label ID="lblRice" runat="server"></asp:Label>
                    </span>
                </td>
                <td class="style9">
                    <span class="style17">
                    <asp:Label ID="lblQRice" runat="server"></asp:Label>
                    </span>
                </td>
            </tr>
            <tr>
                <td class="style14">
                    &nbsp;</td>
                <td class="style20">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style14">
                    Side Dishes :</td>
                <td class="style20">
                    <span class="style17">
                    <asp:Label ID="Label6" runat="server" Visible="False"></asp:Label>
                    </span>
                </td>
                <td>
                    <span class="style17">
                    <asp:Label ID="Label16" runat="server" Visible="False"></asp:Label>
                    </span>
                </td>
            </tr>
            <tr>
                <td class="style14">
                    &nbsp;</td>
                <td class="style20">
                    <span class="style17">
                    <asp:Label ID="Label7" runat="server" Visible="False"></asp:Label>
                    </span>
                </td>
                <td>
                    <span class="style17">
                    <asp:Label ID="Label17" runat="server" Visible="False"></asp:Label>
                    </span>
                </td>
            </tr>
            <tr>
                <td class="style15">
                </td>
                <td class="style21">
                    <span class="style17">
                    <asp:Label ID="Label8" runat="server" Visible="False"></asp:Label>
                    </span>
                </td>
                <td class="style16">
                    <span class="style17">
                    <asp:Label ID="Label18" runat="server" Visible="False"></asp:Label>
                    </span>
                </td>
            </tr>
            <tr>
                <td class="style14">
                    &nbsp;</td>
                <td class="style20">
                    <span class="style17">
                    <asp:Label ID="Label9" runat="server" Visible="False"></asp:Label>
                    </span>
                </td>
                <td>
                    <span class="style17">
                    <asp:Label ID="Label19" runat="server" Visible="False"></asp:Label>
                    </span>
                </td>
            </tr>
            <tr>
                <td class="style14">
                    Beverages :</td>
                <td class="style20">
                    <span class="style17">
                    <asp:Label ID="lblMangoJ" runat="server"></asp:Label>
                    </span>
                </td>
                <td>
                    <span class="style17">
                    <asp:Label ID="lblQMangoJ" runat="server"></asp:Label>
                    </span>
                </td>
            </tr>
            <tr>
                <td class="style14">
                    &nbsp;</td>
                <td class="style20">
                    <span class="style17">
                    <asp:Label ID="lblCendol" runat="server"></asp:Label>
                    </span>
                </td>
                <td>
                    <span class="style17">
                    <asp:Label ID="lblQCendol" runat="server"></asp:Label>
                    </span>
                </td>
            </tr>
            <tr>
                <td class="style14">
                    &nbsp;</td>
                <td class="style20">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style14">
                    Delivery Method :</td>
                <td class="style20">
                    <span class="style17">
                    <asp:Label ID="lblDelivery" runat="server"></asp:Label>
                    </span>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style14">
                    &nbsp;</td>
                <td class="style20">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style14">
                    Total :</td>
                <td class="style20">
                    <span class="style17">
                    <asp:Label ID="lblTotal" runat="server"></asp:Label>
                    </span>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style14">
                    &nbsp;</td>
                <td class="style20">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style14">
                    Grand Total(Inclusive GST) :</td>
                <td class="style20">
                    <span class="style17">
                    <asp:Label ID="lblTotalWGST" runat="server"></asp:Label>
                    </span>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style14">
                    &nbsp;</td>
                <td class="style20">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style14">
                    &nbsp;</td>
                <td class="style20">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style14">
                    &nbsp;</td>
                <td class="style20">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style14">
                    &nbsp;</td>
                <td class="style20">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
        </table>
        <br />
        <br />

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

2 个答案:

答案 0 :(得分:2)

每个aspx都有一个page指令,告诉编译器在哪里查找其代码文件

<%@ Page CodeFile="Lab4.aspx.cs"  %>

documentation

答案 1 :(得分:2)

你的aspx页面实际上应该是这样的。

<%@ Page Title="" Language="C#" MasterPageFile="" AutoEventWireup="true" CodeBehind="Lab4.aspx.cs" Inherits="" %>

CodeBehind =“Lab4.aspx.cs”是指定C#中代码隐藏文件的位置。