private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
conn.open();
string strSQL = "SELECT * FROM errordata ORDER BY id DESC";
SqlCommand mycommand = new SqlCommand(strSQL,conn.dbconn);
string id;
string errinf;
string errcont;
string qingk = "";
this.Label1.Text = qingk;
try
{
SqlDataReader myReader = mycommand.ExecuteReader();
while(myReader.Read())
{
id = myReader.GetValue(0).ToString();
errinf = myReader.GetValue(1).ToString();
errcont = myReader.GetValue(2).ToString();
this.Label1.Text = this.Label1.Text +id+"<br>";
this.Label1.Text = this.Label1.Text +errinf + "<br>";
this.Label1.Text = this.Label1.Text +errcont + "<br>";
this.Label1.Text = this.Label1.Text + "<hr>";
} }
catch
{}
conn.close();
}
private void Button1_Click(object sender, System.EventArgs e)
{
if(this.Page.IsValid)
{

string ErrorTitle = Server.HtmlEncode(this.tbTopIc.Text.Trim());
string ErrorMatter = Server.HtmlEncode(this.tbMatter.Text.Trim());

conn.open();
string strSql="INSERT INTO errordata (ErrorInf,ErrorMatter) VALUES ('"+ErrorTitle+"','"+ErrorMatter+"')";

SqlCommand mycommand=new SqlCommand(strSql,conn.dbconn);
mycommand.ExecuteNonQuery(); conn.close(); this.Label2.Text = ErrorMatter.ToString();
}

}

解决方案 »

  1.   

    button_click()
    最后加一句:
    Response.Redirect("你的aspx页面")
      

  2.   

    检测浏览器刷新
    http://www.microsoft.com/china/msdn/library/webservices/asp.net/BedrockAspNet.mspx
      

  3.   

    写在 !page.ispostback里面看看!
      

  4.   

    可以用这种办法实现防止重复提交
    private void Page_Load(object sender, System.EventArgs e)
    {
    Session["Refresh_id"]=false;
    if(!PostBack)
    {
    Session["Refresh_id"]=true;
    }
    }private void Button1_Click(object sender, System.EventArgs e)
    {
    if(Session["Refresh_id"]==true)
    {
      //数据库插入
    }
    }