前面有加个
if(is什么post)了啦,我忘记了

解决方案 »

  1.   

    楼主应该是page_Load事件中漏写了一个判断:
     protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               .....
               .....//加上你自己的代码
            }
        }
      

  2.   

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Data.OleDb;public partial class ly : System.Web.UI.Page
    {
        public static readonly string CONN_STRING_NON_DTC = System.Configuration.ConfigurationManager.AppSettings["provider"].ToString() + System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["dbPath"]) + ";";    OleDbConnection conn1 = new OleDbConnection(CONN_STRING_NON_DTC);
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            { }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {        if (TextBox1.Text != "")
            {
                if (TextBox4.Text == Session["CHKCode"].ToString())
                {
                    conn1.Open();
                    string name = TextBox1.Text;
                    string email = TextBox2.Text;
                    string qq = TextBox3.Text;
                    string lx = DropDownList1.SelectedValue; //特殊
                    string tit = TextBox5.Text;
                    string con = TextBox6.Text;
                    string strAddSql = "Insert into ly (name,email,qq,lx,tit,con)";
                    strAddSql += "values ('" + name + "','" + email + "','" + qq + "','" + lx + "','" + tit + "','" + con + "')";
                    OleDbCommand comm518 = new OleDbCommand(strAddSql, conn1);
                    comm518.ExecuteNonQuery();
                    Response.Write("<script>alert('留言成功')</script>");
                    TextBox1.Text = "";
                    TextBox2.Text = "";
                    TextBox3.Text = "";
                    TextBox5.Text = "";
                    TextBox6.Text = "";
                    conn1.Close();
                }
                else
                {
                    Response.Write("<script>alert('验证码不正确')</script>");
                }        }
            else
            {
                Response.Write("<script>alert('标题不得为空')</script>");
            }    }
    }代码  我得怎么改
      

  3.   

    留言成功之后,你代码是把一些textbox设置为了""
    ,这样的话 状态还是停留在当前点击按钮的状态,看到的页面上所有textbox为空只是个错觉(可以这么理解)简单的办法就是,断开conn1之后再response.redirect("页面.aspx");  试试吧