今天做了个后台登录页面!
用到了两个textbox控件,一个button按钮!一个linkButton!
当我什么都做好后,点linkbutton时,它没有跳转到注册页面[color=#3366FF]!(注:里面的URL我加了!)
这是为何!!!那位高手能否解释一下!!!![/color]
后台登录页面的代码::
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;
using System.Data.SqlClient;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["DBConnectionString"]); //创建连接对象
SqlCommand cmd = new SqlCommand("select * from one where UserId='" + loginName.Text + "'", conn); //创建查询用户名是否存在数据对象
try
{
conn.Open(); //打开连接
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read()) //如果用户名输入正确
{
if (sdr["UserPwd"].ToString() == TextBox1.Text)//密码正确
{
conn.Close();
Session["UserId"] = loginName.Text.Trim();//存储用户名
Response.Redirect("AddressList.aspx"); //进入系统
}
else
{
Response.Write("<script language=javascript>alert('密码错误!')</script>");
}
}
else
{
Response.Write("<script language=javascript>alert('用户名错误或不存在!')</script>");
}
}
catch (System.Exception ee)
{
Response.Write("<script language=javascript>alert('" + ee.Message.ToString() + "')</script>");
}
finally
{
conn.Close();
}
}
}
用到了两个textbox控件,一个button按钮!一个linkButton!
当我什么都做好后,点linkbutton时,它没有跳转到注册页面[color=#3366FF]!(注:里面的URL我加了!)
这是为何!!!那位高手能否解释一下!!!![/color]
后台登录页面的代码::
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;
using System.Data.SqlClient;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["DBConnectionString"]); //创建连接对象
SqlCommand cmd = new SqlCommand("select * from one where UserId='" + loginName.Text + "'", conn); //创建查询用户名是否存在数据对象
try
{
conn.Open(); //打开连接
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read()) //如果用户名输入正确
{
if (sdr["UserPwd"].ToString() == TextBox1.Text)//密码正确
{
conn.Close();
Session["UserId"] = loginName.Text.Trim();//存储用户名
Response.Redirect("AddressList.aspx"); //进入系统
}
else
{
Response.Write("<script language=javascript>alert('密码错误!')</script>");
}
}
else
{
Response.Write("<script language=javascript>alert('用户名错误或不存在!')</script>");
}
}
catch (System.Exception ee)
{
Response.Write("<script language=javascript>alert('" + ee.Message.ToString() + "')</script>");
}
finally
{
conn.Close();
}
}
}
"<asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/Register.aspx">注 册</asp:LinkButton>"
linkbutton是从页面是进行链接的!
" <asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/Register.aspx">注 册 </asp:LinkButton>"
没看到你的哪个按钮事件... 在这里跳转
private void LinkButton1_Click(object sender, System.EventArgs e)
{
}在页面上可以用超链接
<a href="超链接地址"/>
{
Response.Redirect("Register.aspx");
}
加上了!还是不行啊!!!
<asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/Register.aspx">注 册 </asp:LinkButton>
private void LinkButton1_Click(object sender, System.EventArgs e)
{
Response.Redirect("~/Register.aspx");
} 在页面上可以用超链接
<a href="超链接地址"/>
可以了怎么能不行呢