因该是登录校验吧!!我刚写了个ajax的登录校验,你拿去改改应该能用吧 aspx文件: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="testlogin.aspx.cs" Inherits="Market.Web.testlogin" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script type="text/javascript"> function chkmem() { var t1=document.getElementById("<%=TextBox1.ClientID%>").value.toString(); var t2=document.getElementById("<%=TextBox2.ClientID%>").value.toString(); var svalue=t1.toString()+"|"+t2.toString(); var webFileUrl = "?Area=" + svalue; var result = ""; var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP"); xmlHttp.open("POST", webFileUrl, false); xmlHttp.send(""); result = xmlHttp.responseText;
if(result=="0") { alert("登录失败!"); } else { window.open("url"); } } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>无标题页</title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <input type="button" value="open" onclick="chkmem()" /> </form> </body> </html> 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; using System.Data.SqlClient;namespace Market.Web { public partial class testlogin : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Area != "") { this.down_bind(Area); } } public static DataSet GetDataSet(string sql) { SqlDataAdapter sda = new SqlDataAdapter(sql, ConfigurationSettings.AppSettings["DBsqlConn"]); DataSet ds = new DataSet(); sda.Fill(ds); return ds; } private string Area { get { if (ViewState["Area"] != null && ViewState["Area"].ToString() != "") { return ViewState["Area"].ToString(); } else { if (Request["Area"] != null && Request["Area"].ToString() != "") { return Request["Area"]; } else { return ""; } } } set { ViewState["Area"] = value; } } private void down_bind(string namepass) { string[] np = namepass.ToString().Split('|'); string mystr = ""; string sql = "select 1 FROM [member] where LoginName='" + np[0].ToString() + "' and password='" + np[1].ToString() + "'"; DataSet ds = GetDataSet(sql); if (ds.Tables[0].Rows.Count != 0) { mystr = "1"; } else { mystr = "0"; } this.Response.Write(mystr); this.Response.End(); } } }
我这么写了根本没有作用啊!!!请高手写全吧呵呵!
this.btnMore.Attributes.Add("onclick", "<script>window.open('" + url + "')</script>");
i = User.Identity.Name;
if (!string.IsNullOrEmpty(i))
{
if (Request.QueryString["t"] != null && Request.QueryString["t"] != "")
{
s = Request.QueryString["t"].ToString();
DataTable dtforumid = ndc.GetForumID(s);
string forumid = dtforumid.Rows[0]["ForumID"].ToString();
string a = Mntop.TopicID.ToString();
string url = string.Format("http://kbs.cnki.net/Forums/{0}/ShowForum.aspx", forumid);
this.btnMore.Attributes.Add("onclick", "<script>window.open('" + url + "')</script>");
}
else
{
DataTable dtt = dp.GetCourseMateList(i);
if (dtt.Rows.Count > 0)
{
i = dtt.Rows[0]["CourseID"].ToString();
}
else
{
i = null;
}
DataTable dtforumid1 = ndc.GetForumID(i);
string forumid1 = dtforumid1.Rows[0]["ForumID"].ToString();
string a1 = Mntop.TopicID.ToString();
string url1 = string.Format("http://kbs.cnki.net/Forums/{0}/ShowForum.aspx", forumid1);
this.btnMore.Attributes.Add("onclick", "<script>window.open('" + url1 + "')</script>");
}
}
else
{
Response.Write("<script>alert('您还没有登录,请登录后使用.');window.history.go(-1);</script>");
Response.End();
}
服务器控件BUTTON弹出新页面 原页面不刷新 而且必须在点击事件下写代码?
到底有没有办法能解决呢?
注意没有你那对<script>标记
aspx文件:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="testlogin.aspx.cs" Inherits="Market.Web.testlogin" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script type="text/javascript">
function chkmem()
{
var t1=document.getElementById("<%=TextBox1.ClientID%>").value.toString();
var t2=document.getElementById("<%=TextBox2.ClientID%>").value.toString();
var svalue=t1.toString()+"|"+t2.toString();
var webFileUrl = "?Area=" + svalue;
var result = "";
var xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
xmlHttp.open("POST", webFileUrl, false); xmlHttp.send("");
result = xmlHttp.responseText;
if(result=="0")
{
alert("登录失败!");
}
else
{
window.open("url");
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<input type="button" value="open" onclick="chkmem()" />
</form>
</body>
</html>
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;
using System.Data.SqlClient;namespace Market.Web
{
public partial class testlogin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Area != "")
{
this.down_bind(Area);
}
}
public static DataSet GetDataSet(string sql)
{
SqlDataAdapter sda = new SqlDataAdapter(sql, ConfigurationSettings.AppSettings["DBsqlConn"]);
DataSet ds = new DataSet();
sda.Fill(ds);
return ds;
}
private string Area
{
get
{
if (ViewState["Area"] != null && ViewState["Area"].ToString() != "")
{
return ViewState["Area"].ToString();
}
else
{
if (Request["Area"] != null && Request["Area"].ToString() != "")
{
return Request["Area"];
}
else
{
return "";
}
}
}
set
{
ViewState["Area"] = value;
}
}
private void down_bind(string namepass)
{
string[] np = namepass.ToString().Split('|');
string mystr = "";
string sql = "select 1 FROM [member] where LoginName='" + np[0].ToString() + "' and password='" + np[1].ToString() + "'";
DataSet ds = GetDataSet(sql); if (ds.Tables[0].Rows.Count != 0)
{
mystr = "1";
}
else
{
mystr = "0";
}
this.Response.Write(mystr);
this.Response.End();
}
}
}