清除文本字段的简单任务

发布于 2025-01-05 15:55:51 字数 1796 浏览 5 评论 0原文

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

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 = "";

    }
}

I am trying to clear two text fields after the data is posted. The page posts back but does not delete the text fields.

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

How can I fix my code below.

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 = "";

    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小霸王臭丫头 2025-01-12 15:55:51

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

查看浏览器是否“有帮助”地为您预填充这些字段。如果是这样,您可以在 aspx 文件中为这些控件添加 AutoComplete="off" 属性

,例如:

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

If you have stepped through your code to determine that the txtComment and txtEmail fields have actually had their .Text values set to String.Empty, then I'd suggest the problem may not be in your code at all.

Look to see if the browser is "helpfully" prefilling those fields for you. If so, you can add an attribute in your aspx file on those controls for AutoComplete="off"

For example:

<asp:TextBox runat="server" id="txtComment" AutoComplete="off" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文