我已经设置了一个页面,其中包含用户可以单击并登录的提交按钮。我需要收集字段值然后执行一些后端操作,但是当单击按钮时,我设置了偶数处理程序方法起来不开火。继承按钮代码:
<asp:Button UseSubmitBehavior="false" CssClass="btn btn-primary" ID="btnTest" runat="server" Text="Submit" OnClick="btnTest_Click" />
代码隐藏:
public partial class SignIn : System.Web.UI.Page
{
protected void Page_Load(Object sender, EventArgs e)
{
btnTest.Click += new EventHandler(this.btnTest_Click);
}
protected void btnTest_Click(Object sender, EventArgs e)
{
string user = username.Value;
string pass = password.Value;
int userid = -1;
RoomSvc.Data.Person[] persons = RoomService.Service.ServiceClient.GetPersons();
RoomSvc.Data.Person pUser = null;
foreach (RoomSvc.Data.Person p in persons)
{
if (p.username == user && p.password == pass)
{
pUser = RoomService.Service.ServiceClient.GetPerson(userid.ToString());
}
else
{
return;
}
}
RoomService.Global.currentUser = pUser;
}
}
我已经尝试了所有的东西,没有任何东西能让它发挥作用,有人可以开导。
编辑:.aspx代码:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="SignIn.aspx.cs" Inherits="RoomService.Account.SignIn" %>
<asp:Content ID="SignInHeader" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="SignInContent" ContentPlaceHolderID="MainContent" runat="server">
<form action="SignIn.aspx" class="form-horizontal well span5 offset5">
<fieldset>
<legend>Sign In</legend>
<div class="control-group">
<label class="control-label" for="input01">Username</label>
<div class="controls">
<input runat="server" type="text" class="input-medium" id="username" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="input01">Password</label>
<div class="controls">
<input runat="server" type="text" class="input-medium" id="password" />
</div>
</div>
<div class="form-actions">
<asp:Button CssClass="btn btn-primary" ID="btnTest" runat="server" Text="Submit" OnClick="btnTest_Click" />
</div>
</fieldset>
</form>
</asp:Content>
答案 0 :(得分:1)
您的表单标记缺少runat =“server
答案 1 :(得分:0)
我明白了。
我必须在Page_Init()中添加事件处理程序而不是Page_Load()