none
把大量TextBox的值一次性设置为空,哪错了? RRS feed

  • 问题

  • 我想把asp.net网页中的各个TextBox的内容都变成空,为什么使用下面的代码,在c#代码中会出现如图的错误?

    TextBox_OppositeSide.Text = "";
    
    TextBox_ManageProject.Text = "";
    TextBox_SubjectMatter.Text = "";
    TextBox_EscapeLeaseDateFrom.Text = "";
    TextBox_EscapeLeaseDateTo.Text = "";
    TextBox_LeaseDateSign.Text = "";
    TextBox_LeaseDtaeFrom.Text = "";
    TextBox_LeaseDateTo.Text = "";
    TextBox_MonthRent.Text = "";
    TextBox_SumRent.Text = "";
    TextBox_YearRent.Text = "";
    TextBox_RateOfRise.Text = "";
    TextBox_LeaseAssureMoney.Text = "";
    TextBox_PenalSum.Text = "";
    TextBox_ReferencePrice.Text = "";
    TextBox_ReferencePriceRemarks.Text = "";
    TextBox_ContractRemarks.Text = "";
    TextBox_PropertyManageMoney.Text = "";
    TextBox_ContractChange.Text = "";
    //=======================================================================
    //更改后如下:
    public void ClearTextBox(params TextBox txt)
    {
        foreach(var t in txt)
        {
            t.Text = string.Empty;
        }
    }
    
    ClearTextBox(
        TextBox_OppositeSide,
        TextBox_ManageProject,
        TextBox_SubjectMatter,
        ...
        TextBox_ContractChange
    );

    ------------------------------图---------------------------



    C# 菜鸟中的雏鸟!提的问题也许很幼稚,但我是认真的。希望看在党国的面子上拉兄弟一把!

    2013年10月18日 8:36

答案

  • params TextBox[] textboxes   //加上[]

    另外,如果你的这个页面上只有文本框,直接拖拽一个普通的Html控件,这样写:

    <input type="reset" value="Reset"/>


    Click For donating:Free Rice For the poor
    For spamming-sender issues, you can either report it at Microsoft Spamming Issue, or just find "Report Spam Here+Number" at Forum Issue;You can also find "Verify Your Account+Number" at "Forum Issue", where you can submit to be confirmed to paste links or images.
    For more things to talk about? StackOverFlow is your choice.

    2013年10月18日 8:43