How to clear textbox value after submit

Posted by Alok under ASP.NET on 5/16/2013 | Points: 10 | Views : 12015 | Status : [Member] | Replies : 5
I have two textbox
one store username and second store password
as
Textbox1.Text=ds.tables[0].rows[0]["username"];
Textbox2.attribute["value"]= ds.tables[0].rows[0]["password"];

i have added a required field validator on these textboxes
After updating my record on submit button..i clear the
both TextBoxes as
Textbox1.Text=" ";
Textbox2.attribute["value"]=" ";

now the problem is that after updating record the required field validator
set focus on TextBox2 showing mesage password required but not on TextBox1.
i don't want required field validator to focus on TextBox2.

Thanks & Regards,
Alokssm



Responses

Posted by: Raj.Trivedi on: 5/16/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hello Alok

You can set the focus on textbox1 check this

after the submit action is completed

in code behind do

Textbox1.Focus();

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved

Alok, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: aswinialuri-19361 on: 5/17/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,
To clear all text boxes in submit button
in a button click event
{
clear(Page.controls);
}
pulic void clear(controlcollection ctrl)
{
for each( control cntrl1 in ctrl)
{
if(cntrl1 is TextBox)
((TextBox)cntrl1).text=string.empty;
}
this code will useful if you need to clear many textboxes in your registration page.
I hope it will useful you
Mark as answer if it helps you
Thanks& Regards

Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Alok, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Alok on: 5/17/2013 [Member] Starter | Points: 25

Up
0
Down
hi,
i am not asking to clear the textboxes that i works fine,
Actually i am asking why required field validator get focued on textpassword only but not on texctusername,
i don't want required field validator to focus on txtpassword.

Thanks & Regards,
Alokssm

Alok, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rasik on: 5/17/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Alok,

Set focus on TextBox1 textbox by using TextBox1.Focus() statement once you update the record.



Alok, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: perfectchourasia-9163 on: 5/20/2013 [Member] Starter | Points: 25

Up
0
Down
Use Below code: -

Textbox1.Text=" ";
Textbox2.Text=" ";



ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Alok, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response