2017-04-05 86 views
0

所以基本上我有網頁的形式名爲Lab4.aspx但每次我按下按鈕,它將始終指向腳本runat =「server」,而不是aspx.cs,也是按鈕改回Button_1當我改變了它設置爲btnSubmitaspx頁面無法連接到aspx.cs文件

<script runat="server"> 

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

    End Sub 
</script> 

對於aspx.cs,我已經改變了公共部分類公共部分類Lab4:System.Web.UI.Page在aspx.cs並將該文件命名爲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> 
+1

使用的代碼,而不是圖像 –

+0

你能告訴你的aspx頁面,我相信你缺少的頁面指令 – Krishna

+1

東西請郵寄的aspx頁面全碼 –

回答

2

你的aspx頁面實際上應該從這樣的事情開始。

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

CodeBehind =「Lab4.aspx.cs」是您指定哪個代碼位於C#文件後面的位置。

2

每一個ASPX將有一個頁面指令,它將告訴編譯器在哪裏尋找它的代碼文件

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

documentation