清除文本字段的简单任务

时间:2012-02-16 01:29:45

标签: c# postback

我想在发布数据后清除两个文本字段。页面回发但不删除文本字段。

txtComment.Text = "";
txtEmail.Text = "";

如何修复下面的代码。

protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["PicID"] != null)
        {
            int vPicID = Convert.ToInt32(Request.QueryString["PicID"]);

            BSComments DTGetComments = new BSComments();
            DataTable DTGetCommentsbyID = DTGetComments.GetCommentsByPicIDs(vPicID);


            //Create User object
            // GetMemberInfo GetMember = new GetMemberInfo();
            // DataTable DAMemberInfo = GetMember.GetmemberInfo(UserID);
            txtComment.Text = "";
            txtEmail.Text = "";
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {

        //Check to see if the Email has an account
         BSComments CheckIFmember = new BSComments();
        DataTable DAMemberInfo = CheckIFmember.CheckIFMemberReturnNameEmail(txtEmail.Text);
        int picid =Convert.ToInt32(Request.QueryString["PicID"]);
        if (DAMemberInfo.Rows.Count > 0)
        {
            String myGuid = "";
            String MemberName = "";
            foreach (DataRow row in DAMemberInfo.Rows)
            {
                myGuid = row["Guid"].ToString();
                MemberName = row["MemberName"].ToString();

            }


            BSComments InstertComments = new BSComments();
            InstertComments.InserComment(picid, txtEmail.Text, txtComment.Text, MemberName, myGuid);
            txtComment.Text = "";
            txtEmail.Text = "";
        }
        else
        {
            txtComment.Text = "You need to have an account to post.";
        }


        txtComment.Text = "";
        txtEmail.Text = "";

    }
}

1 个答案:

答案 0 :(得分:2)

如果您已完成代码以确定txtComment和txtEmail字段实际上已将其.Text值设置为String.Empty,那么我建议问题可能根本不在您的代码中。

查看浏览器是否“帮助”为您填写这些字段。如果是这样,您可以在aspx文件中为AutoComplete="off"

的那些控件添加一个属性

例如:

<asp:TextBox runat="server" id="txtComment" AutoComplete="off" />