一个很郁闷的问题?
我做的是文章的后台管理.我在一个页面的IFRAME窗口中显示一类文章的列表并在后面加上编辑,删除的文字链接.链接的页面也是在这个IFRAME中显示.在我没有用后台账号登录时,我按那个删除或编辑.会弹出<请先登录>窗口,但是在我按到5,6次时就会出现错误(String Uid = Session["Uid"].ToString();).有时要10几次,不知道这到底哪里出现在问题...会的大虾给指点下我.
我做的是文章的后台管理.我在一个页面的IFRAME窗口中显示一类文章的列表并在后面加上编辑,删除的文字链接.链接的页面也是在这个IFRAME中显示.在我没有用后台账号登录时,我按那个删除或编辑.会弹出<请先登录>窗口,但是在我按到5,6次时就会出现错误(String Uid = Session["Uid"].ToString();).有时要10几次,不知道这到底哪里出现在问题...会的大虾给指点下我.
解决方案 »
- 字符串的判断
- DataList中找不到控件了!在线等待
- 为什么登录不到指定页面呢,没有显示错误啊
- 大家帮忙看看一个很简单的问!!asp.net
- 都说做图片类网站显示图片用DATALIST,那用DATALIST如何显示3行6列?只剩下20分了。
- 怎样控制DataGrid中超级连接列的文字显示长度呀
- 哪位高手快点帮我把这麻烦去掉,我急用
- 如何给自定义控件增加一个客户端可以访问的到属性?
- 偶是初学asp.net用什么工具好一些?解决问题者一律给分。
- 以前的ASP中的 ActiveXObject("Microsoft.XMLHTTP") 现.net什么类可以实现相同功能?
- 未找到元素的什么什么架构信息,是什么意思啊?
- 插入access数据库小数问题!
出错是因为Session["Uid"]为空了。不能tostring()转换前先判断不为空。
刚也碰到了这样一个问题...
再比如:dropdownlist控件的内容在赋值前也要先检查下是否为空.特别是级联菜单.
id.SelectedIndex>-1
<aspx页面就不贴了>
//HouTai.aspx.cn
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.Sql;
using System.Data.SqlClient;public partial class HouTai_HouTai : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String uid = this.Lab_loginName.Text;
if (!IsPostBack)
{
if (uid == "")
{
this.Lab_loginName.Text = "您尚未<a href='#' onclick='popup_show()'>登录</a>!";
Session["Uid"] = "";
}
else
{
this.Lab_loginName.Text = "欢迎您:" + uid; }
}
} //登录验证
protected void Btn_Login_Click(object sender, EventArgs e)
{
String MyConStr = ConfigurationManager.ConnectionStrings["MyConStr"].ConnectionString;
String login_uid =Server.HtmlEncode(this.Txb_Uid.Text);
String login_pwd =Server.HtmlEncode(this.Txb_Pwd.Text);
SqlConnection con = new SqlConnection();
con.ConnectionString = MyConStr;
SqlCommand cmd = new SqlCommand();
String txtSql = "select Pwd from admin where (Uid='" + login_uid + "');";
cmd.CommandText = txtSql;
cmd.Connection = con; try
{
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
String pwd_temp = sdr["Pwd"].ToString();
pwd_temp = pwd_temp.Trim();
if (login_pwd == pwd_temp)
{
Response.Write("<script>alert('登录成功!');</script>");
Session["Uid"] = login_uid;
this.Lab_loginName.Text = " 欢迎您:" + login_uid;
con.Close();
} else
{
Response.Write("<script>alert('密码错误!');</script>");
Response.Write("<script language=javascript>window.location.href='HouTai.aspx'</script>");
}
}
else
{
con.Close();
Response.Write("<script>alert('用户名不存在!');</script>");
Response.Write("<script language=javascript>window.location.href='HouTai.aspx'</script>");
}
}
catch (Exception ex)
{
Response.Write(ex.ToString());
} }
}
//addNews.aspx.cn这个页面在上个页面的IFRAME中显示.
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.Sql;
using System.Data.SqlClient;
using System.Runtime;public partial class HouTai_addNews : System.Web.UI.Page
{ String MyConStr = ConfigurationManager.ConnectionStrings["MyConStr"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
//添加新闻 protected void Btn_AddNews_Click(object sender, EventArgs e)
{
String Uid = Session["Uid"].ToString();
String newstitle = this.Txb_NewsTitle.Text;
String newscontent = this.Ftb_NewsContent.Text;
kknet kk = new kknet(); if (Uid == "" || Uid == null)
{
Response.Write("<script lauguage=javascript>alert('请先登录!');history.back();</script>");
Response.Write("<script lauguage=javascript>window.location.href='addNews.aspx'</script>");
} else
{ if (newstitle == "")
{
Response.Write("<script lauguage=javascript>alert('标题不能为空!');history.back();</script>");
Response.Write("<script>window.parent.Management.location.href('HNews.aspx')</script>");
}
SqlConnection con = new SqlConnection();
con.ConnectionString = MyConStr; SqlCommand cmd = new SqlCommand("insert into news (Title,Auther,News_Content,News_Time) values ('" + newstitle + "','" + Uid + "','" + newscontent + "','" + kk.getNowDate() + "');", con);
try
{
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{ Response.Write(ex.ToString()); } Response.Write("<script>alert('增加成功!');history.back();</script>");
Response.Write("<script language=javascript>window.parent.Management.location.href('HNews.aspx')</script>");
}
}
}
还有就是有id登录,多按几次也会出现这种状况.感觉5楼的说法可能性比较大,但要怎么解决....还有一点忘记说了就是:我在本地测试没事,只有上传到空间时才会出现的.
通过div或JQUERY弹出窗口