0
我對於使用C#來說很新,而且我遇到了一個問題,就是一旦單擊按鈕就用C#來處理表單數據。基本上我試圖做的是捕獲用戶的信息,一旦表單按鈕被點擊,分配給一個會話,然後顯示在另一個頁面上。這裏是我的C#代碼:C#網頁表單處理
using System;
using System.Web.UI;
public partial class Data : Page
{
protected void btnSubmit(object sender, EventArgs e)
{
string name = Request.Form["username"];
if (string.IsNullOrEmpty(name))
{
// string usr_err = "You did not supply a username???";
return;
}
// make the string uppercase
string upperCase = name.ToUpper();
string greeting = "Welcome " + upperCase + "! Did you know that October is called Oktober in German?";
Session["username"] = upperCase;
Session["greeting"] = greeting;
Response.Redirect("test.aspx", false);
}
}
這是我的HTML(login.apsx):
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Data.cs" Inherits="CS" %>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Login</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="styles.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script type="text/javascript" src="bootstrap-hover-dropdown.js"></script>
<style type="text/css">
body {
background-color: #fff;
}
.form-control {
border: thin solid #000;
}
#main-col {
border-radius: 20px;
border: thin solid #000;
padding: 20px;
box-shadow: 10px 10px 5px rgba(0,0,0,1);
color: rgba(50, 99, 149, 1);
}
</style>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" data-role="navigation">
<div class="container-fluid">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
<span class="sr-only">Toggle Navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-left">
<li><p class="navbar-text navbar-left" style="color: #000;"><b> Login</b></p></li>
</ul>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="col-md-12">
<p class="text-center"><br><br><br>Manipulating data server side<br><br><br></p>
</div>
</div>
<div clas="row-fluid">
<div id="wrapper">
<div id="sidebar-wrapper">
<ul class="sidebar-nav">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</div>
<div class="col-md-6 col-md-push-3" id="main-col">
<form id="login" runat="server">
<div class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control" name="username" id="username" placeholder="Enter username here" runat="server" />
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" name="password" id="password" placeholder="Enter password here" runat="server" />
</div>
<div class="form-group">
<asp:Button id="btnSubmit" Text="Submit" OnClick="btnSubmit" runat="server" />
</div>
</form>
</div>
</div>
</div>
</body>
</html>
我遇到這個編譯錯誤,雖然我不知道爲什麼:
Line 2: using System.Web.UI;
Line 3:
Line 4: public partial class Data : Page
Line 5: {
Line 6: protected void btnSubmit(object sender, EventArgs e)
(Line 4 is where the error occurs).
如果這有幫助,這裏有一些關於它通過編譯器的更多細節:
說明:在co期間發生錯誤mpilation爲請求提供服務所需的資源。請查看以下具體的錯誤細節並適當修改您的源代碼。
編譯器錯誤消息:ASPNET:確保在 定義的類該代碼文件匹配的「繼承」屬性,並且其延伸 正確的基類(例如頁或用戶控件)
任何幫助,將不勝感激,
謝謝!
我剛剛也看到了。謝謝 :) – user2101411