//default.aspx.csusing System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Data.OleDb; using System.Data.SqlClient; using System.Runtime.InteropServices; using System.Configuration; using System.Web.UI.WebControls; using System.Web.Services.Description; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Button4.Attributes.Add("onclick", "window.open('Register.aspx')");//通过button4打开链接 string strConnection = ConfigurationManager.AppSettings["Str.Properties.Settings.masterConnectionString"].ToString(); SqlConnection objConnection = new SqlConnection(strConnection); objConnection.Open(); SqlCommand cmd = new SqlCommand("select * from judging where name='" + TextBox1.Text.Trim() + "'", objConnection); string sql = "select * from judging where name='" + TextBox1.Text + "'and password='" + TextBox2.Text + "'"; cmd.CommandText = sql; /* *********************************************************************************************** *判断是否有此ID,ExecuteScalar() return the first column of the first row in the result set. */ if (cmd.ExecuteScalar() == null)//无此用户 { Label1.Text = "Sorry, please check your id and psw"; Button3.Visible = false; } else { Label1.Text ="Welcome to "+TextBox1.Text; Button3.Visible = true; } } protected void Button1_Click(object sender, EventArgs e) { Panel1.Visible = false; Panel2.Visible = true; } protected void Button4_Click(object sender, EventArgs e) { } protected void Button3_Click(object sender, EventArgs e) { } protected void LinkButton1_Click(object sender, EventArgs e) { }}
//default.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!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> <link rel="Stylesheet" href="mystyle.css" mce_href="mystyle.css" type="text/css" /></head><body> <form id="form1" runat="server"> <div class="tt"> <div class="menu"> Online Judge</div> <div class="menu"> </div> <div class="menu"> </div> <div class="menu" align="center"> <asp:Panel ID="Panel1" runat="server" Height="127px"> Login<br /> <br /> username<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> password<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <br /> <br /> <asp:Button ID="Button1" runat="server" οnclick="Button1_Click" Text="submit" /> <asp:Button ID="Button4" runat="server" Text="Register" /> </asp:Panel> <asp:Panel ID="Panel2" runat="server" Visible="False"> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <br /> <asp:Button ID="Button3" runat="server" οnclick="Button3_Click" Text="修改密码" /> <br /> <br /> <input type="button" οnclick="window.location='Register.aspx'" value="注册新用户" /> </asp:Panel> </div> </div> </form></body></html>
body {}.menu{ margin:10px; padding:10px; font-size:14px; display:block; float:left; background-image:url(pic/bglogin.png); background-position:center; background-repeat:repeat-x; border-style:solid; border-width:3px; width:20%; height:90%; }.menu ul{ background-color:#41428b; color:White; width:100%;}.tt{ height:150px;}
//Register.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="Register" %><!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></head><body> <form id="form1" runat="server"> <div align="center"> <asp:CreateUserWizard ID="CreateUserWizard1" runat="server" BackColor="#F7F6F3" BorderColor="#E6E2D8" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" Height="267px" oncreateduser="CreateUserWizard1_CreatedUser" Width="318px"> <SideBarStyle BackColor="#5D7B9D" BorderWidth="0px" Font-Size="0.9em" VerticalAlign="Top" /> <SideBarButtonStyle BorderWidth="0px" Font-Names="Verdana" ForeColor="White" /> <ContinueButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" /> <NavigationButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" /> <HeaderStyle BackColor="#5D7B9D" BorderStyle="Solid" Font-Bold="True" Font-Size="0.9em" ForeColor="White" HorizontalAlign="Center" /> <CreateUserButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" /> <TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <StepStyle BorderWidth="0px" /> <WizardSteps> <asp:CreateUserWizardStep runat="server"> <ContentTemplate> <table border="0" style="font-family:Verdana;font-size:100%;height:267px;width:318px;"> <tr> <td align="center" colspan="2" style="color:White;background-color:#5D7B9D;font-weight:bold;" mce_style="color:White;background-color:#5D7B9D;font-weight:bold;"> 注册新帐户</td> </tr> <tr> <td align="right"> <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">用户名:</asp:Label> </td> <td> <asp:TextBox ID="UserName" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="必须填写“用户名”。" ToolTip="必须填写“用户名”。" ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">密码:</asp:Label> </td> <td> <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox> <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" ErrorMessage="必须填写“密码”。" ToolTip="必须填写“密码”。" ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">确认密码:</asp:Label> </td> <td> <asp:TextBox ID="ConfirmPassword" runat="server" ontextchanged="ConfirmPassword_TextChanged" TextMode="Password"></asp:TextBox> <asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server" ControlToValidate="ConfirmPassword" ErrorMessage="必须填写“确认密码”。" ToolTip="必须填写“确认密码”。" ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">电子邮件:</asp:Label> </td> <td> <asp:TextBox ID="Email" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="EmailRequired" runat="server" ControlToValidate="Email" ErrorMessage="必须填写“电子邮件”。" ToolTip="必须填写“电子邮件”。" ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="QuestionLabel" runat="server" AssociatedControlID="Question">安全提示问题:</asp:Label> </td> <td> <asp:TextBox ID="Question" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="QuestionRequired" runat="server" ControlToValidate="Question" ErrorMessage="必须填写“安全提示问题”。" ToolTip="必须填写“安全提示问题”。" ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="right"> <asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">安全答案:</asp:Label> </td> <td> <asp:TextBox ID="Answer" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="AnswerRequired" runat="server" ControlToValidate="Answer" ErrorMessage="必须填写“安全答案”。" ToolTip="必须填写“安全答案”。" ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td align="center" colspan="2"> <asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password" ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="“密码”和“确认密码”必须匹配。" ValidationGroup="CreateUserWizard1"></asp:CompareValidator> </td> </tr> <tr> <td align="center" colspan="2" style="color:Red;" mce_style="color:Red;"> <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal> </td> </tr> </table> </ContentTemplate> </asp:CreateUserWizardStep> <asp:CompleteWizardStep runat="server" /> </WizardSteps> </asp:CreateUserWizard> </div> </form></body></html>
//Register.aspx.csusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Data.OleDb;using System.Data.SqlClient;using System.Runtime.InteropServices;using System.Configuration;using System.Web.UI.WebControls;using System.Web.Services.Description; public partial class Register : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) { String user = CreateUserWizard1.UserName.ToString(); String psw = CreateUserWizard1.Password.ToString(); String psw2 = CreateUserWizard1.ConfirmPassword.ToString(); string strConnection = ConfigurationManager.AppSettings["Str.Properties.Settings.masterConnectionString"].ToString(); SqlConnection objConnection = new SqlConnection(strConnection); objConnection.Open(); SqlCommand cmd = new SqlCommand("select * from judging where name='" + user + "'", objConnection); /* *********************************************************************************************** *判断是否有此ID,ExecuteScalar() return the first column of the first row in the result set. */ if (cmd.ExecuteScalar() == null)//无此用户 { Response.Write("OK"); string user1 = CreateUserWizard1.UserName.ToString(); string psw1 = CreateUserWizard1.Password.ToString(); string sql = "insert into judging (userid,name,password) values('" + 50 + "','" + user1 + "','" + psw1 + "')"; cmd.CommandText = sql; cmd.ExecuteNonQuery(); } else { Response.Write("已创建此用户,please try another username"); } } protected void ConfirmPassword_TextChanged(object sender, EventArgs e) { }}
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow