读书人

asp.net 跳转页面 总是在新标签页打开

发布时间: 2013-06-19 10:26:41 作者: rapoo

asp.net 跳转页面 总是在新标签页打开
使用Redirect跳转页面却始终在新标签页打开,我写的其他页面用这个方法就是在当前标签页打开的,不知道为什么这个就始终在新标签页打开

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace Classmates
{
public partial class joinClass : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindToGridView();
string name = string.Empty;
if (Session["name"] == null)
{
name = "登录";

}
else
{
name = Session["name"].ToString();


}
if (name == "登录")
{

LinkButton3.Visible = false;
LinkButton1.Text = name;
//HyperLink1.NavigateUrl = "UserLogin.aspx";
LinkButton2.Text = "立即注册";
//HyperLink2.NavigateUrl = "UserRegister.aspx";
}
else
{
LinkButton1.Text = name;
LinkButton2.Text = "退出";
LinkButton3.Visible = true;


LinkButton3.Text = "未找到班级?立即创建";
// HyperLink2.NavigateUrl = "joinClass.aspx";
/*Session["name"] = null;
HyperLink1.Text = "登录";
HyperLink1.NavigateUrl = "UserLogin.aspx";
HyperLink2.Text = "立即注册";
HyperLink2.NavigateUrl = "UserRegister.aspx"; */
;

}


}

}
private void BindToGridView()
{
string connectionstring = ConfigurationManager.ConnectionStrings["conn"].ToString();
SqlConnection conn2 = new SqlConnection(connectionstring);
conn2.Open();
string sqlString = "select * from class order by cno asc ";
SqlDataAdapter sda = new SqlDataAdapter(sqlString, conn2);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
conn2.Close();



}
protected void LinkButton1_Click(object sender, EventArgs e)
{
//登录时的单击操作
if (LinkButton1.Text == "登录")
{
Response.Redirect("http://localhost:9665/UserLogin.aspx");
}
}

protected void LinkButton2_Click(object sender, EventArgs e)


{
if (LinkButton2.Text == "立即注册")
{
Response.Redirect("http://localhost:9665/UserRegister.aspx");

}
if (LinkButton2.Text == "退出")
{
Session["name"] = null;
Response.Redirect("http://localhost:9665/joinClass.aspx");
LinkButton1.Text = "登录";
LinkButton2.Text = "立即注册";
}

}

protected void LinkButton3_Click(object sender, EventArgs e)
{
if (Session["name"] !=null)
{

Response.Redirect("http://localhost:9665/createClass.aspx");


}
}

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{

Response.Redirect("http://localhost:9665/RegisterInClass.aspx");


}

protected void Button1_Click(object sender, EventArgs e)
{
string date = DropDownList1.SelectedValue;
string kd = TextBox1.Text.Trim();
string connectionstring = ConfigurationManager.ConnectionStrings["conn"].ToString();
SqlConnection conn2 = new SqlConnection(connectionstring);
conn2.Open();
string sqlString = "select * from class where cdate = '" + date + "' or cname like '%" + kd + "%' order by cno asc ";
SqlDataAdapter sda = new SqlDataAdapter(sqlString, conn2);


DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
conn2.Close();



}

}
}


[解决办法]
看看这个是否对你有帮助
[解决办法]
在header中设置<base target="_self"> 如果想从其他窗口打开的,在那个标签上单独设置

读书人网 >asp.net

热点推荐