新手提问(关于用户控件)
Login.ASCX.CS
namespace boleStudent
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
/// <summary>
/// Login 的摘要说明。
/// </summary>
public class Login : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.TextBox Name;
protected System.Web.UI.WebControls.TextBox Pass;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button2_Click(object sender, System.EventArgs e)
{
Response.Redirect("Register.aspx");
}
}
}
login.ascx
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="Login.ascx.cs" Inherits="boleStudent.Login" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<script language="C#" runat="server">
</script>
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="300" border="1">
<TR>
<TD>用户名:</TD>
<TD><asp:TextBox id="Name" runat="server"></asp:TextBox></TD>
<TD>a</TD>
</TR>
<TR>
<TD>密码:</TD>
<TD><asp:TextBox id="Pass" runat="server" TextMode="Password"></asp:TextBox></TD>
<TD>a</TD>
</TR>
<TR>
<TD></TD>
<TD>
<asp:Button id="Button1" runat="server" Text="登陆"></asp:Button>
<asp:Button id="Button2" runat="server" Text="注册新用户" OnClick="Button2_Click"></asp:Button></TD>
<TD>a</TD>
</TR>
</TABLE>
然后预览时为什么说Button2_Click在LOGIN.ASCX中没有定义?哪位高手帮帮忙!
------解决方案--------------------
<asp:Button id="Button2" runat="server" Text="注册新用户" OnClick="Button2_Click">
------->
<asp:Button id="Button2" runat="server" Text="注册新用户" >