protected void btn_cancel_Click(object sender, EventArgs e)
        {
            this.txt_username.Text = "";
            this.txt_pass.Text = "";
        }
txt_username
txt_pass
这二个是文本框控件。
代码的功能是把文本框内容,清空的功能。请问一下,上面的这个代码,写的是不是没有C#代码的风格?
这个代码该怎么写?

解决方案 »

  1.   

    C#就这风格了 
    lz说的是变量命名规范吧
      

  2.   

    你这啥风格都没
     
    我要是有50个表单 你咋办?  
    而且 还有下拉框的选项也要重置到 "请选择"
    什么textAre radiobutton 就不说了
      

  3.   


         
            function clearalltext()
            {
                document.getElementById("txt_username").value ="";
                document.getElementById("txt_pwd").value ="";
            }
      

  4.   

            protected void btn_cancel_Click(object sender, EventArgs e)
            {
                txtusername.Text = "";
                txtpass.Text = "";
    或者
     tbxusername.Text = "";
                tbxpass.Text = "";
            }
      

  5.   

                this.txt_username.Text = this.txt_pass.Text = string.Empty;
      

  6.   

    表单少的话 就一个一个写吧.
    上了10个的话 
    还是写个通用的JS方法吧.
    毕竟重置这种东西 到后台做 体验度太差.JS的写法的话 
    具体就是遍历 input 然后判断input类型 再来进行不同的重置操作
      

  7.   

    foreach (Control c in this.form1.Controls)
                {
                    if (c is TextBox)
                    {
                        (c as TextBox).Text = string.Empty;
                    }
                }
      

  8.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript" language="javascript" src="jquery-1.3.2.js"></script>
    <script>
    $(
       function()
    {

    $("#clear").click(function(){
    //重置TextBox
    $(":input").each(
      function()
    {
    if($(this).attr("type")=="text")
    {$(this).val('');}
    }
     );
    //重置下拉框
    $("select").each(
    function()
    {
    $(this).val('0');
    }
     );
    });
    }
      );
    </script>
    </head><body>
    <form>
    <input type="text" id="a1" />
    <input type="text" id="a2" />
    <input type="text" id="a3" />
    <select>
    <option value="0">--请选择--</option>
    <option value="1">123</option>
    <option value="2">321</option>
    </select>
    <select>
    <option value="0">--请选择--</option>
    <option value="1">123</option>
    <option value="2">321</option>
    </select>
    <input type="button" id="clear" value="重置"/>
    </form>
    </body>
    </html>Jquery 写的 需要下个Jquery的库 网上直接搜下 然后把头部的Src改下
      

  9.   

    js或者用html控件就能搞定的东西,没必要这样写
      

  10.   

    这倒是典型c#风格了,尤其是玩asp.net的C# style大多数玩其他语言的都基本不会把 “重置”这个功能非要放到后端代码里去做,因为他们都知道html的input类型实际就一个reset类型是专门做这玩意滴<input type="reset" value="重置" />