想搞一个通用函数,能够将恢复页面的默认状态。

解决方案 »

  1.   

    最笨的方法,写循环一个一个来.dropdownlist1.selectindex=-1;
    或者重定向本页,相当于f5
      

  2.   

    最一个方法把下面代码加上,可以清空页面所TextBox的值
    foreach(Control   ctl   in   Page.Controls[1].Controls)
    {
    switch(ctl.GetType().ToString())
       {
    case   "System.Web.UI.WebControls.TextBox":
    ((TextBox)ctl).Text="";
    break;
    default:
    break;
       }
    }
      

  3.   

    manually clear all the entry fields controls may cause the page code 
    become tight-coupled, but it'll be the most efficient way. Also, if you 
    want to make it more flexible, you can use the FindControl method to find 
    all the enty fields controls thorugh the control ID and reset their text 
    property, but this will be much less efficient. the best way to do this (assuming you can hard code your form) is to make the reset a standard HTML button: <INPUT TYPE=BUTTON onClick="javascript:clearForm()" NAME="FormToClear"> and then code up some client side script to clear each of the form fields - Pseudo code: function clearForm() { 
    document.formname.FormToClear.value = "" 
    ... etc 

      

  4.   

    foreach(Control control in Page.Controls[1].Controls)
    {
    switch(control .GetType().ToString())
    {
    case "System.Web.UI.WebControls.TextBox":
    ((TextBox)control ).Text = "";
    break;
    case "System.Web.UI.WebControls.DropDownList":
    DropDownList ddl = (DropDownList)control ;
    ddl.SelectedIndex = -1;
    break;
    }
    }