blah blah blah is here! blah blah » Close

up0down
link

This is my code:

protected void Button1_Click(object sender, EventArgs e)
{
string s1 = TextBox1.Text;
string s2 = TextBox2.Text;
string s3 = TextBox3.Text;
blog b = new blog();
if (TextBox3.Text.Length > 100)
{
Label2.Text = "Please enter less than 100 characters, please...";
}
else
{
Label2.Text = "Thanks for sharing...";
b.Insertblog(s1, s2, s3);
}

//I've set maxLength property of first two textboxes set to 20,20

}


By this code I've inserted data into a XML file. Data is entered. But after entering data the values remain in the textboxes. I want to clear it. How can this be done?

last answered 2 years ago

4 answers

up1down
link

protected void Button1_Click(object sender, EventArgs e)
{
blog b = new blog();

// You could always set TextBox3 Maxlength to 100 and get rid of this if....
if (TextBox3.Text.Length > 100)
{
Label2.Text = "Please enter less than 100 characters, please...";
}
else
{
Label2.Text = "Thanks for sharing...";
b.Insertblog(Textbox1.Text,Textbox2.Text, Textbox3.Text);
}

Textbox1.Text = string.Empty;
Textbox2.Text = string.Empty;
Textbox3.Text = string.Empty;

//I've set maxLength property of first two textboxes set to 20,20
}

up0down
link

Its not working . any idea?

vulpes
17279

If the textboxes are not clearing, are any of them bound to a data source?

up0down
link

From those TextBoxes I'm inserting data to my XML file (it's in APP_DATA folder). I have two methods[GetBlig() and InsertBlog()] in my blog.cs file and as you see, I created one object instance of blog class and overloading the constructor with the values taken from those TextBoxes.

The link you can check here:

http://aspspider.info/lokhu/Memeber/Default.aspx

vulpes
17279

Is it possible that you could be reloading the textboxes with the previous data following a postback?

up0down
link

vulpes, I've solved the problem from your clue. The TextBoxes are databind(), so I changed the code this way:

string s1;
string s2;
string s3;
protected void Button1_Click(object sender, EventArgs e)
{
string s1 = TextBox1.Text;
string s2 = TextBox2.Text;
string s3 = TextBox3.Text;
blog b = new blog();
if (TextBox3.Text.Length > 100)
{
Label2.Text = "Please enter less than 100 characters, please...";
}
else
{
Label2.Text = "Thanks for sharing...";
b.Insertblog(s1, s2, s3);
}

//I've set maxLength property of first two textboxes set to 20,20
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
}

Feedback