你的TextBox初始化语句 要放在
if(!Page.IsPostBack) 中

解决方案 »

  1.   

    selectindexchange()是不是在page_load()里也调用了阿
      

  2.   

    发现在点击了提交button后button的OnClick内好像有调用了selectindexchange()
    我怎么都看不出来 哪里有引发了ddl的selectindexchange啊protected  void btnEditTemplate_Click(object sender,EventArgs e)
    {
      string str1=txtTemplateName.Text;
      string str2=txtTemplateContent.Text;
      string str3=lstTemplateName.SelectedItem.Value;
      string str4=lstTemplateName.SelectedItem.Text;
      OleDbCommand commTest=new OleDbCommand("select count(*) from Template where TemplateName='"+txtTemplateName.Text+"'",Conn);
      Conn.Open();
      int i=int.Parse(commTest.ExecuteScalar().ToString());
      Conn.Close();
      if(i>0)
      {
             Response.Write("<script>alert('已经有此名称的模板存在');</script>");
      }
      else
      {
    string strInsert;
    if(str1=="")
    {
    Response.Write("<script>alert('"+str2+"');</script>");
    strInsert="update Template  set TemplateContent= '"+str2+"' where ID= ";
    strInsert+=str3;
    Response.Write("<script>alert('"+strInsert+"');</script>");
    }
    else
    {
    strInsert="update Template  set TemplateName='"+str1+"',TemplateContent= '"+str2+"' where ID= ";
    strInsert+=str3;
    string strUpdate="update Article set TemplateName='"+str1+"' where TemplateName='"+str4+"'";
    Conn.Open();
    OleDbCommand comm2=new OleDbCommand(strUpdate,Conn);
    comm2.ExecuteNonQuery();
    Conn.Close();
    }
    Conn.Open();
    OleDbCommand comm=new OleDbCommand(strInsert,Conn);
    comm.ExecuteNonQuery();
    Conn.Close();
       }
    }
      

  3.   

    我也遇到过这种情况,就像Englishgenius(白天遛鸟晚上洗澡)说得一样
    你的TextBox初始化语句 要放在
    if(!Page.IsPostBack) 中
        这样就可以解决了!
      

  4.   

    to: ugg(许优) 
    我已经放倒if(!Page.IsPostBack) 中了 但是仍然不对
    按钮点击后竟然可以引发DDL的autopostback,郁闷
      

  5.   

    autopostback
    是不是都申明了?
      

  6.   

    只在DDL中申明了AUTOPOSTBACK
    我纳闷的是 为何提交按钮会触发DDL的autopostback而引发了selectIndexchange
      

  7.   

    AUTOPOSTBACK为true的textbox建议用会话状态!
      

  8.   

    to:szwebnet(动力)
    textbox没有设autopostback啊,只是DDL用了AUTOPOSTBACK并在selectindexchange内给TEXTBOX赋值,但赋值后 我手工更改了TEXTBOX的内容  点击提交button 却还能激发DDL的autopostback 导致TEXTBOX的内容提交倒数据库内的仍然是改前的值
      

  9.   

    恕本人无知.你所谓的DDL是什么?
    Data Definition Language?就算不是.即然是autopostback,那还用button去激发?不解中~
      

  10.   

    to: szwebnet(动力) 
    DDL我指的是dropdownlist
    我设计是当DDL选项发生改变时 textbox的也随着内容也发生改变,比如通过选择DDL内的一个ID
    textbox内容显示为此ID相对应的name值,这个已经通过ddl的autopostback+selectindexchange对应的方法实现。
    然后修改手工textbox内容点击button提交可以修改name的值。
    问题是button点击后又引发了ddl的selectindexchanged那个方法导致textbox的内容又回倒手工更改前并提交倒数据库了,即修改未成功。
    但button的click()内更本没有掉用ddl的selectindexchanged那个方法导致啊button的click代码已经在上边贴着。
      

  11.   

    搞定 ~~~viewstate的问题 
    感谢大家热心帮助  结贴!