Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 24th, 2008, 08:06 AM
Registered User
 
Join Date: Mar 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to clear textboxes after submitting.

Hi, I have a simple app that searches by first and last name and displays results in a gridview. When I submit the text stays in the textboxes and I need to clear that somehow. Using textbox1.text = "" doesn't work because that just clears out the results from the gridview.

Thanks.

 
Old March 24th, 2008, 09:39 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You are probably clearing the TextBoxes BEFORE you bind your grid. Consider:

textBox1.Text = "";
textBox2.Text = "";
//Create some query to bind the GridView
GridView1.DataSource = ds;
GridView1.DataBind();

This obviously will return no results to your grid since the values you create you query on are blank so try this instead:

//Create some query to bind the GridView
GridView1.DataSource = ds;
GridView1.DataBind();
textBox1.Text = "";
textBox2.Text = "";

Also, if you are handling the TextChanged event for these textboxes you will first need to remove the EventHanlder since changing the Text in code can cause thise event handler to fire:

textBox1.TextChanged -= new EventHandler(<TextChanged Event>);
textBox2.TextChanged -= new EventHandler(<TextChanged Event>);
textBox1.Text = "";
textBox2.Text = "";
textBox1.TextChanged += new EventHandler(<TextChanged Event>);
textBox2.TextChanged += new EventHandler(<TextChanged Event>);

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old March 24th, 2008, 12:32 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Doug is correct with his first code suggestion.

However, I believe the latter part isn't quite accurate. In a windows form app programmatically changing a textbox value will cause a text changed event to fire. However, in the ASP.NET page model, postback event handlers are only called once to reflect the user's action. You should be safe even without detaching and attaching the textbox TextChanged handlers. It's easy enough to try just the first fix and see if that clears up the problem.

-Peter
peterlanoie.blog
 
Old March 24th, 2008, 12:41 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Mmmm yep! Windows Form Programming != Web Form Programming. >< I think I may have needed a longer vacation. Thanks for clearing this up Peter.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old March 24th, 2008, 12:59 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

No prob! As usual Doug, I got your back! ;)

I went to a Silverlight 2.0 presentation recently. Now that Silverlight will support CLR languages in the client space, it's going to get even harder to distinguish the line between client and server code in Silverlight web apps. But it's WAY cool to see Visual Studio jump from debugging client side C# to server side C#. I have a feeling we'll be answering a lot of questions on p2p when that is released.

-Peter
peterlanoie.blog
 
Old March 24th, 2008, 02:04 PM
Registered User
 
Join Date: Mar 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you.

Here is a problem I am having though. The results show up in the gridview, but when I try to edit, the record disappears. I guess because there isn't a value in the textboxes. Any idea how to fix this?






Similar Threads
Thread Thread Starter Forum Replies Last Post
form submitting cro_crx Pro PHP 5 January 25th, 2005 12:19 PM
Form Submitting cro_crx Beginning PHP 3 January 17th, 2005 01:30 PM
Submitting a form YuliaKupina Classic ASP Basics 3 June 24th, 2004 01:52 AM
Chapter 3, submitting a form YuliaKupina BOOK: Beginning ASP 3.0 1 June 23rd, 2004 03:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.