webForm的password问题
生活真美好 2004-03-13 05:25:43 问题:
1、html部分c_UserPass已设置内容,但显示页面时为空,怎么解决。
2、CS部分,c_UserPass1不可用,如何解决。
能否详细说明,谢谢各位。
html部分
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<TABLE id="Table2" cellSpacing="2" cellPadding="2" width="100%" border="2">
<tr>
<td align="right" width="120">用户名称:</td>
<td align="left" width="120"><asp:textbox id="c_UserName" runat="server" Width="100px" ToolTip="请输入myname" MaxLength="20">myname</asp:textbox></td>
<td align="right" width="120">用户密码:</td>
<td align="left" width="120"><asp:textbox id="c_UserPass" runat="server" Width="100px" ToolTip="请输入mypass" MaxLength="20"
TextMode="Password">mypass</asp:textbox></td>
<td align="left" width="120"><INPUT id="c_UserPass1" type="password" value="mypass1"></td>
<td style="COLOR: #0066ff" vAlign="middle" align="center"><asp:button id="c_UserEnter" runat="server" Text="用户登录"></asp:button></td>
</tr>
</TABLE>
</form>
</body>
</HTML>
CS部分
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebApplication1
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox c_UserName;
protected System.Web.UI.WebControls.TextBox c_UserPass;
protected System.Web.UI.WebControls.Button c_UserEnter;
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.c_UserEnter.Click += new System.EventHandler(this.c_UserEnter_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void c_UserEnter_Click(object sender, System.EventArgs e)
{
if (c_UserPass1.Text.Trim() == "")
{
Response.Write ("<script>alert(\"请输入用户名称和密码! (不允许为空)\")</script>");
}
}
}
}