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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Guest UserPosted Nov 5, 2016, 1:00 AM
Ifour HirenPosted Nov 3, 2016, 7:54 AM
{
foreach (Control c in Page.Controls)
{
if ((c.GetType() == typeof(TextBox)))
{
((TextBox)(c)).Text = "";
}
}
}
above code helps you to make it working.
Nitin ChoudharyPosted Jan 20, 2015, 7:23 AM
TextLastAddress.Text=string.Empty;
TextAgeText=string.Empty;
Or
TextFirstName.Text="";
TextLastAddress.Text="";
TextAgeText="";
Kunal ASscapePosted Jan 5, 2015, 12:57 AM
Ajith JosephPosted Feb 4, 2013, 8:10 AM
Pradip PandeyPosted Dec 6, 2012, 10:21 PM
TextBoxAddress.Text=string.Empty;
TextBoxSalary.Text=string.Empty;
Hope it will help.
oscarchenPosted Dec 6, 2012, 10:15 AM
address.Text= '' '';
Satyapriya NayakPosted Dec 6, 2012, 8:32 AM
Satyapriya NayakPosted Dec 6, 2012, 8:15 AM
<%@ 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" %>
nallyaPosted Dec 6, 2012, 7:28 AM
textbox1.text="";
ex::
txtname.text="";
txtaddress.text="";
txtsalary.text="";