我要建立一个登陆页面,页面中间有用户名和密码输入框那种最简单的.
把输入框和按钮放在表格中最好是吗?这样表格有align:center属性时,这些控件都在页面中间.
如果这样,表格要手工写代码吗? 具体怎么实现?写程序时应该手工写代码呢,还是使用VS.net IDE? 看了快速入门教程,好像都是手工代码,那一定要熟悉html了是吗?迷茫...
把输入框和按钮放在表格中最好是吗?这样表格有align:center属性时,这些控件都在页面中间.
如果这样,表格要手工写代码吗? 具体怎么实现?写程序时应该手工写代码呢,还是使用VS.net IDE? 看了快速入门教程,好像都是手工代码,那一定要熟悉html了是吗?迷茫...
在熟悉html后,就可以用VS.net IDE开始学习asp.net编程了!“面中间有用户名和密码输入框那种最简单的.把输入框和按钮放在表格中最好是吗”
是的.
如果页面布局是FlowLayout,最好用表格定位控件!"如果这样,表格要手工写代码吗? 具体怎么实现?"
表格不需要手工写代码,只要从控件面板拖到页面中就可以了!
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 216px; POSITION: absolute; TOP: 80px" runat="server"></asp:TextBox>
<asp:Label id="Label2" style="Z-INDEX: 106; LEFT: 160px; POSITION: absolute; TOP: 120px" runat="server">密 码:</asp:Label>
<asp:Label id="Label1" style="Z-INDEX: 105; LEFT: 160px; POSITION: absolute; TOP: 80px" runat="server">用户名:</asp:Label>
<asp:Button id="Button2" style="Z-INDEX: 104; LEFT: 224px; POSITION: absolute; TOP: 160px" runat="server"
Text="登录"></asp:Button>
<asp:Button id="Button1" style="Z-INDEX: 103; LEFT: 296px; POSITION: absolute; TOP: 160px" runat="server"
Text="取消"></asp:Button>
<asp:TextBox id="TextBox2" style="Z-INDEX: 102; LEFT: 216px; POSITION: absolute; TOP: 120px"
runat="server"></asp:TextBox>
</form>
</body>
</HTML>
=====================================================<%@ Page language="c#" Codebehind="Login.aspx.cs" AutoEventWireup="false" Inherits="Market.Login" %>
<html>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="Table5">
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0" id="Table6">
<tr>
<td align="center">
<table width="70%" border="0" cellspacing="0" cellpadding="0" id="Table7">
<tr>
<td nowrap><table width="100%" border="0" cellpadding="2" cellspacing="0" class="wenben" id="Table8">
<tr>
<td nowrap>用户登录:</td>
</tr>
<tr>
<td nowrap><table width="40%" border="0" cellpadding="1" cellspacing="1" class="loginbox" id="Table9">
<TR>
<TD noWrap align="right" width="36%" bgColor="#e0e0e0">请选择用户类型:</TD>
<TD width="64%" bgColor="#e0e0e0">
<asp:DropDownList id="ddlType" runat="server">
<asp:ListItem Value="个人用户" Selected="True">个人用户</asp:ListItem>
<asp:ListItem Value="商贸公司">商贸公司</asp:ListItem>
</asp:DropDownList></TD>
</TR>
<tr>
<td width="36%" align="right" bgcolor="#e0e0e0" nowrap>用户名:</td>
<td width="64%" bgcolor="#e0e0e0">
<asp:TextBox id="txtLoginID" runat="server" Width="120px" MaxLength="60"></asp:TextBox>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="txtLoginID"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td align="right" bgcolor="#f0f0f0">密码:</td>
<td bgcolor="#f0f0f0">
<asp:TextBox id="txtLoginPwd" runat="server" Width="120px" TextMode="Password" MaxLength="12"></asp:TextBox>
<asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server" ErrorMessage="*" ControlToValidate="txtLoginPwd"></asp:RequiredFieldValidator></td>
</tr>
</table>
</body></html>
==========================================================================
以上为.aspx文件内容.
以下为.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;
using System.Web.Security;namespace Market
{
/// <summary>
/// Login 的摘要说明。
/// </summary>
public class Login : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtLoginID;
protected System.Web.UI.WebControls.TextBox txtLoginPwd;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.Button btnLogin;
protected System.Web.UI.WebControls.Button btnGetPwd;
protected System.Web.UI.WebControls.TextBox txtValidateCode;
protected System.Web.UI.WebControls.DropDownList ddlType;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
int iLogin = CheckLogin();
if(iLogin == 0)//现在登录为公司用户
{
ddlType.SelectedIndex = 1;
ddlType.Enabled = false;
btnLogin.Attributes.Add("onclick","return confirm('系统检查到您已经以个人身份登录了,点确定将注销当前登录并改变身份登录.');");
}
else if(iLogin == 1)//现在登录为个人
{
ddlType.SelectedIndex = 0;
ddlType.Enabled = false;
btnLogin.Attributes.Add("onclick","return confirm('系统检查到您已经以公司身份登录了,点确定将注销当前登录并改变身份登录.');");
}
else
{
ddlType.SelectedIndex = 0;
}
}
}
private int CheckLogin()
{
if(Session["Login_ID"] != null && Session["Co_ID"] == null)//个人
{
return 0;
}
else if(Session["Login_ID"] == null && Session["Co_ID"] != null)//公司
{
return 1;
}
else
{
return 2;
}
}
======================================
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
this.btnGetPwd.Click += new System.EventHandler(this.btnGetPwd_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private bool CheckValidateCode(string strCode)
{
if(Request.Cookies["CheckCode"] == null)
{
return false;
}
else
{
if(Request.Cookies["CheckCode"].Value == strCode)
{
return true;
}
else
{
return false;
}
}
}
private void btnLogin_Click(object sender, System.EventArgs e)
{
if(ddlType.SelectedValue == "个人用户")
{
Session.Remove("Co_ID");
LoginUser();
}
else
{
Session.Remove("Login_ID");
LoginCo();
}
} private void LoginCo()
{
if(Page.IsValid == true)
{
Classes.Corporation cor = new Market.Classes.Corporation();
if(CheckValidateCode(txtValidateCode.Text.Trim()) == false)
{
txtValidateCode.Text = "";
Response.Write("<script>alert('验证码错误!')</script>");
return;
}
else if( cor.Login(txtLoginID.Text.Trim(),txtLoginPwd.Text.Trim()) == false )
{
txtValidateCode.Text = "";
Response.Write("<script>alert('您输入的公司名或密码有误!')</script>");
return;
}
else //用户验证成功。
{
Session["Co_ID"] = txtLoginID.Text.Trim();
if(Request.QueryString["fromUrl"] == null)
{
Response.Write("<script>alert('登录成功,点确定返回首页!');window.navigate('Default.aspx');</script>");
return;
}
else
{
Response.Redirect("ProccAlert.aspx?fromUrl=" + Request.QueryString["fromUrl"]);
}
}
}
} private void LoginUser()
{
if(Page.IsValid == true)
{
Classes.User user = new Market.Classes.User();
if(CheckValidateCode(txtValidateCode.Text.Trim()) == false)
{
txtValidateCode.Text = "";
Response.Write("<script>alert('验证码错误!')</script>");
return;
}
else if( user.UserLogin(txtLoginID.Text.Trim(),txtLoginPwd.Text.Trim()) == false )
{
txtValidateCode.Text = "";
Response.Write("<script>alert('您输入的用户名或密码有误!')</script>");
return;
}
else //用户验证成功。
{
Session["Login_ID"] = txtLoginID.Text.Trim();
if(Request.QueryString["fromUrl"] == null)
{
Response.Write("<script>alert('登录成功,点确定返回首页!');window.navigate('Default.aspx');</script>");
return;
}
else
{
Response.Redirect("ProccAlert.aspx?fromUrl=" + Request.QueryString["fromUrl"]);
}
// if(Request.QueryString["fromUrl"] == null)//else
// {
// // see if user clicked on the signin link
// if (FormsAuthentication.GetRedirectUrl(Session["Login_ID"].ToString(), false).ToLower().EndsWith("default.aspx"))
// {
// // creates authentication ticket for user then display confirmation
// FormsAuthentication.SetAuthCookie(Session["Login_ID"].ToString(), false);
// if(Request.QueryString["fromUrl"] != "")
// {
// Response.Redirect("ProccAlert.aspx?from=" + Request.QueryString["fromUrl"]);
// }
// else
// {
// Response.Redirect("ProccAlert.aspx?from=" + Request.ServerVariables["HTTP_REFERER"]);
// }
// }
// else
// {
// // user came here by accessing a secure page, continue
// // on to the page they were trying to access
// FormsAuthentication.RedirectFromLoginPage(Session["Login_ID"].ToString(), false);
// }
// }
}
}
} private void btnGetPwd_Click(object sender, System.EventArgs e)
{
Response.Redirect("Forgetpwd.aspx");
}
}
}