asp.net button事件?
protectedvoidButton3_Click(objectsender,EventArgse){HttpCookiecookie=Request.Cookies[...
protected void Button3_Click(object sender, EventArgs e)
{
HttpCookie cookie=Request.Cookies["CheckCode"];
if (TextBox3.Text.ToString() == cookie.Value)
{
if (Session["uname"]==null)
{
Response.Write("<script>'请登录后评论'</script>");
}
else
{
string uname = this.Session["uname"].ToString();
string createdate = DateTime.Now.ToString();
string vid = Request.QueryString["vid"];
string message = Request.Form["S1"];
SqlConnection con = new SqlConnection("Data Source=20110313-2022;Initial Catalog=VOD;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = @"insert into [message]
(uname,createdate,vid,message) values
(@uname,@createdate,@vid,@message)";
cmd.Parameters.AddWithValue("@uname", uname);
cmd.Parameters.AddWithValue("@createdate", createdate);
cmd.Parameters.AddWithValue("@vid", vid);
cmd.Parameters.AddWithValue("@message", message);
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script>'评论成功'</script>");
}
}
else
{
Response.Write("<script>'验证码错误'</script>");
}
}
上面是我写的代码,怎么点击button3的时候一点反应也没有,既不提示没登陆,也不提示验证码错误,信息也写不进数据库。 展开
{
HttpCookie cookie=Request.Cookies["CheckCode"];
if (TextBox3.Text.ToString() == cookie.Value)
{
if (Session["uname"]==null)
{
Response.Write("<script>'请登录后评论'</script>");
}
else
{
string uname = this.Session["uname"].ToString();
string createdate = DateTime.Now.ToString();
string vid = Request.QueryString["vid"];
string message = Request.Form["S1"];
SqlConnection con = new SqlConnection("Data Source=20110313-2022;Initial Catalog=VOD;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = @"insert into [message]
(uname,createdate,vid,message) values
(@uname,@createdate,@vid,@message)";
cmd.Parameters.AddWithValue("@uname", uname);
cmd.Parameters.AddWithValue("@createdate", createdate);
cmd.Parameters.AddWithValue("@vid", vid);
cmd.Parameters.AddWithValue("@message", message);
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script>'评论成功'</script>");
}
}
else
{
Response.Write("<script>'验证码错误'</script>");
}
}
上面是我写的代码,怎么点击button3的时候一点反应也没有,既不提示没登陆,也不提示验证码错误,信息也写不进数据库。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询