Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to clear all the controls of an aspx page(form)?

Posted on 2010-08-20
3
Medium Priority
?
489 Views
Last Modified: 2013-12-17
How to clear all the controls of an aspx page
My page has combo boxes , text boxes , radio buttons etc
Client side:
i tried
document.forms[0].reset();
Did not work as its supposed to only for html pages

Server side:
this.form1.Controls.Clear();
the above statement gave me an error. y?

What is the solution using client side javascripting?
AND also if we have to do this from server side?
0
Comment
Question by:heyne230
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 12

Expert Comment

by:UnexplainedWays
ID: 33489893
are you using any js libs (moo / jq), if so you could do a simple select from the form and get all input/select/checkbox's and then set them back to default values.

You could do it from the code behind and iterate recursively and find all the controls that are the same type and also reset.

Are you wanting to reset on a js action, or when the form posts and you want it to be cleared?
0
 
LVL 6

Accepted Solution

by:
thaytu888888 earned 2000 total points
ID: 33490115
- Try codes below:
var frm_elements = yourFormName.elements;

for(i=0; i<frm_elements.length; i++) {

field_type = frm_elements[i].type.toLowerCase();

switch(field_type) {

case "text":
case "password":
case "textarea":
case "hidden":

elements[i].value = "";
break;

case "radio":
case "checkbox":

if (elements[i].checked) {

elements[i].checked = false;

}
break;

case "select-one":
case "select-multi":

elements[i].selectedIndex = -1;
break;

default:
break;
}
}

Open in new window

0
 
LVL 16

Expert Comment

by:Vikram Singh Saini
ID: 33490854
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question