我一直在为我的 asp.net 网站主题使用 twitter-bootstrap,但在尝试让一个简单的按钮执行事件时遇到了一些麻烦。该按钮是一个 asp 组件,从我在论坛中读到的内容是 bootstrap 不能很好地管理 asp.net 组件,无论是脚本(最明显)还是 CSS 问题(我不知道,我不是正在发生的事情的专家)。
据我所见,当我将按钮放在表单中时,它会采取行动,但据我所知,这不是应该采取的行动。
并使用以下参数重定向到同一页面:
?ctl00%24MainContent%24LogUsernameText=&ctl00%24MainContent%24LogPasswordText=&ctl00%24MainContent%24loginBtn=Sign+In%21
我尝试了许多在其他人的问题中看到的答案,例如将其呈现为 HTML 按钮并制作它runat="server"
,然后在页面加载时为其添加一个实例。
我怎样才能度过这个难关?
来自母版页的代码:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Main.master.cs" Inherits="Main" %>
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="css/bootstrap.min.css">
<style>
body {
padding-top: 60px;
padding-bottom: 40px;
}
</style>
<link rel="stylesheet" href="css/bootstrap-responsive.min.css">
</head>
<body>
<!--[if lt IE 7]>
<p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
<![endif]-->
<form id="form1" runat="server">
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="Home.aspx">bitRain</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li><a href="Home.aspx">Home</a></li>
<li><a href="Upload.aspx">Upload</a></li>
<li><a href="FAQ.aspx">FAQ</a></li>
</ul>
<ul class="nav pull-right">
<li><a href="LoginN'Register.aspx">Sign Up</a></li>
<li class="divider-vertical"></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Sign In <b class="caret"></b></a>
<ul class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">
<form id="navSignIn">
<li>Username</li>
<li><asp:TextBox ID="UsernameField" runat="server"></asp:TextBox></li>
<li>Password</li>
<li><asp:TextBox ID="PasswordField" runat="server"></asp:TextBox></li>
<li><asp:CheckBox ID="navRemember" runat="server" Text="Remember Me." /></li>
<li><asp:Button ID="navLoginBtn" runat="server" Text="Sign In" CssClass="btn" style="clear: left; width: 100%; height: 32px; font-size: 13px;" /></li>
</form>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class="container">
<div class="hero-unit">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
<hr>
<footer>
<p>bitRain Project</p>
</footer>
</div>
<!-- /container -->
<script src="http://code.jquery.com/jquery-2.0.0.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/main.js"></script>
</form>
</body>
页面中的代码块:
<div class="span6 form-horizontal">
<div class="heading">
<legend class="form-heading">Sign In</legend>
</div>
<div class="control-group">
<label class="control-label" for="inputUsername">Username</label>
<div class="controls">
<asp:TextBox ID="LogUsernameText" runat="server"></asp:TextBox>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<asp:TextBox ID="LogPasswordText" runat="server" TextMode="Password"></asp:TextBox>
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<asp:CheckBox ID="LogRemember" runat="server" Text="Keep me signed in |" />
<a href="#" class="btn btn-link">Forgot my password</a>
</label>
<asp:Button ID="loginBtn" runat="server" CssClass="btn" Text="Sign In!" Width="220px" OnClick="loginBtn_Click" />
</div>
</div>
</div>
.cs 文件上的代码:
public partial class LoginN_Register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void loginBtn_Click(object sender, EventArgs e)
{
Account log = new Account();
string username = LogUsernameText.Text;
string password = LogPasswordText.Text;
string authentication = log.UserLogin(username, password);
if (!string.IsNullOrEmpty(authentication))
{
// Create a new ticket used for authentication
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1, // Ticket version
username, // Username associated with ticket
DateTime.Now, // Date issued
DateTime.Now.AddMinutes(30), // Date to expire
true, // "true" for a persistent user cookie
authentication, //Role
FormsAuthentication.FormsCookiePath); //Path authorized
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(
FormsAuthentication.FormsCookieName, hash);
if (ticket.IsPersistent) cookie.Expires = ticket.Expiration;
Response.Cookies.Add(cookie);
string returnUrl = Request.QueryString["ReturnUrl"];
if (returnUrl == null) returnUrl = "~/Users/User_Profile.aspx";
Response.Redirect(returnUrl);
base.OnLoad(e);
}
else
{
Alert.Text = "<div class=\"alert alert-error\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\">×</button><strong>Warning!</strong> Best check yo self, you're not looking too good.<div>";
LogUsernameText.Text = "Fail";
}
}
}
我的猜测是有一些脚本重定向我的按钮事件。我找不到它。我正在使用最新版本的引导主题。