Hi Friends
I have a form in asp.net, there are many field on that form i.e. name,address,salary etc. I want when we click on submit button then all textboxes will be clear ? Please tell me how to do this ?
Please help me ?
Thanks
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Dec 6, 2012, 3:15 AM EST
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Clear_textboxes_asp.net._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace Clear_textboxes_asp.net
{
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
CleartextBoxes(this);
}
public void CleartextBoxes(Control parent)
{
foreach (Control c in parent.Controls)
{
if ((c.GetType() == typeof(TextBox)))
{
((TextBox)(c)).Text = "";
}
if (c.HasControls())
{
CleartextBoxes(c);
}
}
}
}
}
Method-2
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Clear_textboxes_asp.net.WebForm1" %>
nallyaRank #8,588 · 219 reputationPosted Dec 6, 2012, 2:28 AM EST
textbox1.text="";
ex::
txtname.text="";
txtaddress.text="";
txtsalary.text="";
Satyapriya NayakRank #47 · 31.5K reputationPosted Dec 6, 2012, 3:32 AM EST
oscarchen2 reputationPosted Dec 6, 2012, 5:15 AM EST
address.Text= '' '';
Pradip PandeyRank #452 · 5.6K reputationPosted Dec 6, 2012, 5:21 PM EST
TextBoxAddress.Text=string.Empty;
TextBoxSalary.Text=string.Empty;
Hope it will help.
Ajith Joseph11 reputationPosted Feb 4, 2013, 3:10 AM EST
Kunal ASscape2 reputationPosted Jan 4, 2015, 7:57 PM EST
Nitin Choudhary113 reputationPosted Jan 20, 2015, 2:23 AM EST
TextLastAddress.Text=string.Empty;
TextAgeText=string.Empty;
Or
TextFirstName.Text="";
TextLastAddress.Text="";
TextAgeText="";
Ifour Hiren61 reputationPosted Nov 3, 2016, 3:54 AM EDT
{
foreach (Control c in Page.Controls)
{
if ((c.GetType() == typeof(TextBox)))
{
((TextBox)(c)).Text = "";
}
}
}
above code helps you to make it working.
Guest UserRank #2,002 · 726 reputationPosted Nov 4, 2016, 9:00 PM EDT