WebForm--j簡單控制項、簡單的登入

來源:互聯網
上載者:User

標籤:

一、簡單控制項

1、label:邊框(邊框的顏色、樣式、粗細)  是專門顯示文字的,   被編譯後是    <span id="Label1">Label</span>

2、Literal:  Text屬性,作用顯示文字  編譯後不會形成任何元素,一般被用來輸出Js代碼,比較靈活

       <asp:Literal ID="Literal2" runat="server" Text="mm"></asp:Literal>

3、Textbox:文字輸入框, 編譯後是:<input name="TextBox3" type="password" id="TextBox3" />

 屬性:  wrap:自動換行,

           Text Mode:可以是文字框、密碼框(password)

           Enabled:可用 或 不可用,編譯後是:<input name="TextBox3" type="password" id="TextBox3" disabled="disabled" class="aspNetDisabled" />

           Readonly:唯讀,

          Maxlength:限制長度,一般用於使用者名稱、密碼的長度。

4、Button:按鈕,編譯後是   <input type="submit" name="Button2" value="Button" id="Button2" />提交按鈕

    OnclientClick:

5、ImageButton:屬性:imageurl:圖片地址,——提交

6、LinkButton:超連結,

7、Hyperlink:

 

 

 

二、簡單登入

.aspx頁面:

   <title></title>   <style type="text/css">       //設定button 按鈕樣式       #Button1 {       width:100px;       height:30px;       background-color:yellow;       color:green;       font-size:18px;       font-family:黑體;       font-weight:bold;       }   </style></head><body>       <form id="form1" runat="server" text="xm">    使用者名稱:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br/>        密碼:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />        //登入的介面        <asp:Button ID="Button1" runat="server" Text="登入" />        <asp:Literal ID="Literal1" runat="server"></asp:Literal>       </form></body></html>

 

 

.cs頁面

 

public partial class zhuce : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        Button1.Click += Button1_Click;//登入按鈕  按兩次Tab    }    void Button1_Click(object sender, EventArgs e)    {        //先把使用者名稱和密碼取出   串連資料庫三個類        string Uname = TextBox1.Text;        string Pwd = TextBox2.Text;        bool isok = new UsersDA().Select(Uname,Pwd);        if (isok)        {            Literal1.Text = "登入成功!";        }        else        {            Literal1.Text = "使用者名稱密碼錯誤";        }    }

 

 

 連結資料庫:

App_Code

沒有命名空間

1、實體類

2、資料訪問類:

public class UsersDA{    SqlConnection conn = null;    SqlCommand cmd = null;    public UsersDA()    {        conn = new SqlConnection("server=.;database=Data0617;user=sa;pwd=100867");        cmd = conn.CreateCommand();    }    /// <summary>    /// 使用者驗證    /// </summary>    /// <param name="Uname">驗證的使用者名稱</param>    /// <param name="Pwd">驗證的密碼</param>    /// <returns></returns>    public bool Select(string Uname,string Pwd)    {        bool has = false;        cmd.CommandText = "select * from Users where [email protected] and [email protected]";        cmd.Parameters.Clear();        cmd.Parameters.AddWithValue("@username",Uname);        cmd.Parameters.AddWithValue("@password",Pwd);        conn.Open();        SqlDataReader dr= cmd.ExecuteReader();        if (dr.HasRows)        {            has = true;        }                conn.Close();        return has;    }

 

WebForm--j簡單控制項、簡單的登入

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.