ASP.net Question

G

Guest

Hi,

I have an ASP.net page. After submitting the form and saving all the form
values I want to give user an option to enter more records ( like reloading
the page with empty fields and clear viewstate)

Is there a way to clear the Page of the existing values or do I have to do
it manually (control by control)

Thnx
 
R

Ryan Ternier

mavrick101 said:
Hi,

I have an ASP.net page. After submitting the form and saving all the form
values I want to give user an option to enter more records ( like reloading
the page with empty fields and clear viewstate)

Is there a way to clear the Page of the existing values or do I have to do
it manually (control by control)

Thnx

The easiest way would be to just use:
Response.Redirect("yourPage.aspx");

That way it's not a postback.
 
G

Guest

Hi Mavrick ,
I don't think there is inbuilt stuff for clearing the form fields.
U can write an function to clear the form Collections. In that way u don't
need to clear one by one.

here the code snippet which might help you to iterate thru the form
collections on server side
private void clearFormControls(){

int ctlCount=Convert.ToInt32(Page.Controls.Count.ToString());
int i;
TextBox tempText = new TextBox();
ListBox templist = new ListBox();

for (i=0; i<amtControl; i++)
{
switch (Page.Controls.GetType())
{
case tempText.GetType():
((TextBox) Page.Controls).Text = "";
break;
case templist.GetType():
((ListBox)Page.Controls).Items.Clear();
break;
default:
break;
}
}
}

In the above define your all page controls whatever u have defined and
accordingly clear i.e dropdown etc and call the clearControls function in
your save routine


U can also write and client javascript function to clear the form
collections and mode of submit and check it in onload if the mode is submit
and success clear the controls

Hope this helps you
Thanks

IntelYogi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top