我想实现的功能是,用户在登陆框那里输入用户名和密码,如果登陆成功即用户名和密码正确
就在原来登陆的那里   用户名:显示刚刚登陆的用户名   密码:这项就不显示啦
代码如下:
帮我看看,我该怎么去写他,是要在HTML代码中嵌入C#还是怎么样???
Default2.aspx页面:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style type="text/css">
<!--
body,td,th {
font-size: 12px;
}
-->
</style></head>
<body>
    <form id="form1" runat="server">
    <div>
        <div style="text-align: center">
            <div style="text-align: center">
              <div style="text-align: center">
                <table width="431" border="0" cellpadding="0" cellspacing="0">
                  <tr>
                    <td width="50" style="height: 28px">用户名:</td>
                    <td width="50" style="height: 28px">
                        <asp:TextBox ID="username" runat="server">username</asp:TextBox></td>
                    <td width="164" style="height: 28px">密码:</td>
                    <td width="167" style="height: 28px">
                        <asp:TextBox ID="pwd" runat="server">pwd</asp:TextBox></td>
                  </tr>
                  <tr>
                    <td colspan="4"><div align="center">
                        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="提交" />&nbsp;</div></td>
                  </tr>
                </table>
              </div>
            </div>
        </div>    </div>
    </form>
</body>
</html>
Default2.aspx.cs页面:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.username.Text = "";
            this.pwd.Text = "";        }    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string username = this.username.Text;
        string pwd = this.pwd.Text;
        string connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("database\\database.mdb");
        OleDbConnection conn = new OleDbConnection(connectionstring);
        conn.Open();        DataSet ds = new DataSet();
        OleDbCommand cm = new OleDbCommand();
        cm.CommandText = "select * from [admin] where username='" + username + "' and password='" + pwd + "'";
        cm.Connection = conn;
        OleDbDataAdapter Adapter = new OleDbDataAdapter();
        Adapter.SelectCommand = cm;
        Adapter.Fill(ds);
        if (ds.Tables[0].Rows.Count > 0)
        {
            Session["login"] =true;
            Session["loginusername"] = username;
            Response.Redirect("Default2.aspx");
        }
        else
        {
            Response.Write("<script>alert('用户名或密码错误')</script>");
            Response.Write("<script>location.href='Default2.aspx'</script");
        }
    }
}也就是在返回的时候
在原来的页面是显示    用户名:显示刚刚登陆的用户名   密码:这项就不显示啦

解决方案 »

  1.   

    <tr>
                        <td width="50" style="height: 28px">用户名:</td>
                        <td width="50" style="height: 28px">
                            <asp:TextBox ID="username" runat="server">username</asp:TextBox></td>
                        <td width="164" style="height: 28px">密码:</td>
                        <td width="167" style="height: 28px">
                            <asp:TextBox ID="pwd" runat="server">pwd</asp:TextBox></td>
                      </tr>
    也就是当也面返回时这里该怎样处理??????
      

  2.   

    protected void Page_Load(object sender, EventArgs e)
    {
                bool login = (bool)Session["login"];
                if (login)
                {
                    this.username.Text = Session["loginusername"].ToString();
                }
                else
                {
                    this.username.Text = "";
                    this.pwd.Text = "";
                }
    }
      

  3.   

    protected void Page_Load(object sender, EventArgs e)
    {
                bool login = false;
                if (Session["login"] != null)
                {
                    login = (bool)Session["login"];
                }
                if (login)
                {
                    this.username.Text = Session["loginusername"].ToString();
                }
                else
                {
                    this.username.Text = "";
                    this.pwd.Text = "";
                }
    }