Asp.Net中帶圖片的重填按鈕

來源:互聯網
上載者:User

把我做第一次做系統時對重填按鈕的實現記錄如下:

第一次用ImageButton可以設定背景圖片,然後在背景Click事件中寫如下 
        this.TxtCallNo.Text = "";
        this.TxtCaller.Text = "";
        this.TxtTranDate.Text = "";
        this.TxtTranLimit.Text = "";
        this.TxtTranNo.Text = "";
        this.TxtTranPres.Text = "";
        this.RadioButton1.Checked = false;
        this.RadioButton2.Checked = false;
        this.DlstUnit.SelectedIndex = 0;
第二次也是用ImageButton,在Click事件中如下寫:
        foreach (Control c in form1.Controls)
        {
            if (c is TextBox)
                ((TextBox)c).Text = "";
            if (c is DropDownList)
                ((DropDownList)c).SelectedIndex = 0;
            if (c is RadioButton)
                ((RadioButton)c).Checked = false;
        }
第三次是用<a href="#"><img src="images/but2.gif" width="61" onclick="ReSet();" />
用JavaScript寫ReSet()方法:
    function ReSet()
    {
        var len=document.form1.elements.length;  
          var i;  
          for (i=0;i<len;i++)  
          { 
          if (document.form1.elements[i].type=="text")  
          {  
            document.form1.elements[i].value="";;  
          }
          if(document.form1.elements[i].type=="radio")
          {
          document.form1.elements[i].checked=false;
          }
          }
          var obj1=document.getElementById("DlstCallerWay");
         
          var obj5=document.getElementById("TxtRemark");
          obj5.value="";
          obj1.selectedIndex=0;
//不能獲得DropDownList 的用戶端type,不知道怎麼獲得的JS沒學過。
//當文字框的TextMode設為multiline時也不能獲得type就只能一個按照ID獲得
    }
這三種方法都是清空不是重設或重填,因為有時重設的要求是控制項內有資料單擊重設按鈕後仍保留原來的

資料,例如TextBox1載入頁面時的值為“胡帥”,單擊後仍是“胡帥”,上面的方法單擊後都清空了。
第四種方法:
<input type="image" src="images/but2.gif" name="reset"
onclick="form1.reset();return false;" />

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.