下面是一个学生退课的程序,为什么在运行的时候该程序总被执行两次???是把它放在page_load里面的原因嘛?请各位告诉我详细的原因,谢谢。
namespace class_select
{
public class delclas:System.Web.UI.Page
{
private void Page_Load(object sender,System.EventArgs e)
{
string getcno = Request["cno"];
try
{
SqlConnection mycon = new SqlConnection("server=localhost;database=mytest;uid=sa;pwd=sa;connect timeout=120");
string delsql="delete from sco where cno='"+getcno+"' and sno='"+Session["sno"]+"'";
SqlCommand cmd = new SqlCommand(delsql,mycon);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
string str="update csee set cpeo=cpeo-1 where cno='"+getcno+"'";
cmd = new SqlCommand(str,mycon);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
string script = "";
script += "<script language=javascript>alert(\"退课成功!\");";
script += " window.opener.location.reload();";
script += " window.close();</script>";
Response.Write(""+script+"");

}
catch 
{
Response.Write("<script>alert(\"请先注册\")</script>");
}
}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
}
}

解决方案 »

  1.   

    AutoEventWireup="false"?
    呵呵,你这个还是asp的方式
      

  2.   

    谢谢楼上的,问题解决了。
    还想问问你从什么地方看出我的还是asp方式,那怎么才能把它改成asp.net方式的呢,谢谢了
      

  3.   

    把代码写在
    if(!IsPostBack)
    {
      ......
    }
      

  4.   

    asp方式:每个操作通过url传递到其他处理页面在pageload的时候接受参数处理
    asp.net方式:按钮有各自的处理事件直接处理
      

  5.   

    谢谢了啊,顺便说一下我用(!IsPostBack)试验过了,不行