清除文本字段的简单任务
我试图在发布数据后清除两个文本字段。该页面回发但不删除文本字段。
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您已单步执行代码以确定 txtComment 和 txtEmail 字段实际上已将其 .Text 值设置为 String.Empty,那么我建议问题可能根本不在您的代码中。
查看浏览器是否“有帮助”地为您预填充这些字段。如果是这样,您可以在 aspx 文件中为这些控件添加
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: