newsoftware.aspx页面有DropDownList控件,id是ddldepartment。点击旁边的ImageButton按钮,跳转到adddepartment.aspx页面,此页面有个文本框id为txtdepartment,和确定按钮。点击确定按钮能成功添加一个部门。问题:为什么添加完之后返回newsoftware.aspx页面的时候没有更新出来啊。疑惑中...adddepartment.aspx.cs
string sqladd="insert into DepartmentInfo(department)"+
  "values('"+txtdepartment.Text+"')";
ClsDB.Execute(sqladd);
Response.Write(" <script>window.opener.document.getElementById('ddldepartment').value='"+this.txtdepartment.Text+"';alert('添加成功!') </script>"); 

解决方案 »

  1.   

    你添加成功后 再跳转到前面的页面  把页面重新加载一次  用response再跳转回去
      

  2.   

    点击旁边的ImageButton按钮,跳转到adddepartment.aspx页面,
    =======
    在本页面上跳转的还是打开的新窗口?
      

  3.   

    我用文本框就能够成功,为什么DropDownList就不行
      

  4.   

    如果是本页面上跳转的,那你在跳转回来就行了(Response.Redirect),要是打开的新窗口,如果是open打开的,就: 
    window.opener.location.reload(true);
    如果是showModalDialog
    window.dialogArguments.location.reload(true);
      

  5.   

     Response.Write(" <script>window.opener.document.getElementById('ddldepartment').value='"+this.txtdepartment.Text+"';alert('添加成功!') </script>"); 这样写对于DropDownList当然是没用的.
    你可以用script刷新一下父页面,来达到你刷新DropDownList的目的
    window.opener.Location = window.opener.Location
      

  6.   


    string sqladd="insert into DepartmentInfo(department)"+
                                  "values('"+txtdepartment.Text+"')";
                    ClsDB.Execute(sqladd);
                    Response.Write(" <script>window.opener.document.getElementById('ddldepartment').value='"+this.txtdepartment.Text+"';alert('添加成功!') </script>"); 你这样写成不成功都弹出添加成功了。
    ClsDB.Execute(sqladd);返回值多少根据返回值做判断
    刷新用window.opener.location.reload(true); 
      

  7.   


    为什么文本框这样用就可以啊。我用了window.opener.Location = window.opener.Location方法,可是提交之后是刷新整个页面,把写的数据都清空了,我想只刷新DropDownList
      

  8.   

    Response.Write(" <script>window.opener.document.getElementById('ddldepartment').value='"+this.txtdepartment.Text+"';alert('添加成功!') </script>"); 
    不太清楚你的意思,不过,如果ddldepartment是服务器控件的话,这里getElementById('ddldepartment')就不用服务器端 ID,而应该换成浏览器解析后的客户端 ID。
    getElementById('"+ddldepartment.ClientID+"')
      

  9.   

    文本框生成的客户端html是<input type="text"..>
    DropDownList则是<select name="DropDownList1" id="DropDownList1"><input>和<select>的区别你不知道?
      

  10.   

    解决方案:newsoftware.aspx页面中放一个<div style="display:none">
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    </div>protected void Button1_Click(object sender, EventArgs e)
    {
       //调用你绑定DropDownList的方法
    }然后把你的代码修改如下:
    string sqladd="insert into DepartmentInfo(department)"+
                                  "values('"+txtdepartment.Text+"')";
                    ClsDB.Execute(sqladd);
                    Response.Write(" <script>window.opener.document.getElementById('Button1').click();alert('添加成功!') </script>"); 这样在你insert完后.用脚本会点一下你父页面的隐藏按钮,达到刷新DropDownList的目的
    而服务器端按钮postback不会导至你的页面重加载,把其它服务器端TextBox的内容刷没window.opener.Location = window.opener.Location会使你的页面重载加.也就是会执行
    Page_load中
    if(!IsPostBack){}中的内容,而按钮postback则不会.
      

  11.   

    string sqladd="insert into DepartmentInfo(department)"+
                                  "values('"+txtdepartment.Text+"')";
                    ClsDB.Execute(sqladd);
    if(sqladd != 0)
    {                Response.Write(" <script>window.opener.document.getElementById('ddldepartment').value='"+this.txtdepartment.Text+"';alert('添加成功!') </script>"); }else
    {
    .......
    }
      

  12.   

    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />