Thought I'd share this since it took me a long time to get it working.
Thanks to a bunch of contributers in Google Groups who shared
javascript, etc.
The question was: How can I put a reset button on my ASP.NET web page,
and have an HTML reset button click clear 1) all validator text display
and 2) validation summary display. Problem was clearing them and yet
still leaving them working and visible if the user immediately began
re-entering data after RESET.
I did it like this:
1) Put HTML Reset button on form.
2) Call a javascript function on Reset button's client-side onclick
event.
3) In the javascript function, reset the appropriate controls.
Note that this works great in Internet Explorer 6.0. However, there are
issues in Mozilla (I tested version 1.7.3). Validation text and summary
still clear, but because of the way that ASP.NET does postback on
submit, Mozilla can't find the original values. Even a plain RESET
button doesn't work right after postback using Mozilla (I tried).
Didn't test Netscape or Firefox.
Reset button:
<INPUT id="btnReset"
onclick="ResetV alidators('Vali dationSummary1' ,'val');" type="reset"
value="Clear Form">
Javascript function:
//*************** *************** *************** *******
// ResetValidators (validationSumm aryId, validationContr olsPrefix)
// Purpose: Resets ASP.NET validation control text display
// AND validation summary control display to empty.
// Inputs: validationSumma ryID - string - id of ValidationSumma ry
// control
// validationContr olsPrefix - string - a prefix to use
// to identify validation controls when looping through all
// span Ids. (Validation controls are represented by spans).
// Outputs: none
//*************** *************** *************** *******
function ResetValidators (validationSumm aryId, validationContr olsPrefix)
{
var spans;
var divValSummary;
if (document.all) {
spans = document.all.ta gs('span');
divValSummary = document.all(va lidationSummary Id);
}
else if (document.getEl ementsByTagName ) {
spans = document.getEle mentsByTagName( 'span');
divValSummary = document.getEle mentsById(valid ationSummaryId) ;
}
if (spans) {
for (var i = 0; i < spans.length; i++) {
var prefixLength = "" + validationContr olsPrefix.lengt h;
var currID = "" + spans[i].id
if ((currID != '') && (prefixLength != '')) {
if (currID.substri ng(0,prefixLeng th) == validationContr olsPrefix) {
//note - set visibility to hidden, not display=none.
// otherwise validator text will never show up again after reset.
spans[i].style.visibili ty='hidden';
}
}
}
}
if (divValSummary) {
// note set display=none, NOT visibility=hidd en. Exact opposite of
// spans above!! Otherwise, validation summary is hidden permanently.
divValSummary.s tyle.display='n one';
}
}
Hope this code is helpful.
Nancy Steinmann
MCSD .NET 1 14362
My "reset" button, just re-requests the page. Would this work for you?
<input type="button" onclick="javasc ript: location.href = location.href;"
value="reset" />
I found it easier to do this, rather than try to clear textboxes, reset drop
down, validators, etc.
HTH,
bill
"NancyASAP" <na************ ***@boeing.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com... Thought I'd share this since it took me a long time to get it working. Thanks to a bunch of contributers in Google Groups who shared javascript, etc.
The question was: How can I put a reset button on my ASP.NET web page, and have an HTML reset button click clear 1) all validator text display and 2) validation summary display. Problem was clearing them and yet still leaving them working and visible if the user immediately began re-entering data after RESET.
I did it like this: 1) Put HTML Reset button on form. 2) Call a javascript function on Reset button's client-side onclick event. 3) In the javascript function, reset the appropriate controls.
Note that this works great in Internet Explorer 6.0. However, there are issues in Mozilla (I tested version 1.7.3). Validation text and summary still clear, but because of the way that ASP.NET does postback on submit, Mozilla can't find the original values. Even a plain RESET button doesn't work right after postback using Mozilla (I tried). Didn't test Netscape or Firefox.
Reset button: <INPUT id="btnReset" onclick="ResetV alidators('Vali dationSummary1' ,'val');" type="reset" value="Clear Form">
Javascript function: //*************** *************** *************** ******* // ResetValidators (validationSumm aryId, validationContr olsPrefix) // Purpose: Resets ASP.NET validation control text display // AND validation summary control display to empty. // Inputs: validationSumma ryID - string - id of ValidationSumma ry // control // validationContr olsPrefix - string - a prefix to use // to identify validation controls when looping through all // span Ids. (Validation controls are represented by spans). // Outputs: none //*************** *************** *************** *******
function ResetValidators (validationSumm aryId, validationContr olsPrefix) { var spans; var divValSummary;
if (document.all) { spans = document.all.ta gs('span'); divValSummary = document.all(va lidationSummary Id); } else if (document.getEl ementsByTagName ) { spans = document.getEle mentsByTagName( 'span'); divValSummary = document.getEle mentsById(valid ationSummaryId) ; } if (spans) { for (var i = 0; i < spans.length; i++) { var prefixLength = "" + validationContr olsPrefix.lengt h; var currID = "" + spans[i].id if ((currID != '') && (prefixLength != '')) { if (currID.substri ng(0,prefixLeng th) == validationContr olsPrefix) { //note - set visibility to hidden, not display=none. // otherwise validator text will never show up again after reset. spans[i].style.visibili ty='hidden'; } } } } if (divValSummary) { // note set display=none, NOT visibility=hidd en. Exact opposite of // spans above!! Otherwise, validation summary is hidden permanently. divValSummary.s tyle.display='n one'; }
}
Hope this code is helpful. Nancy Steinmann MCSD .NET This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Roger Price |
last post by:
Thank you to Yang (Is that your first name?) and Andy for your suggestions.
I am 99% of the way there but now cannot get the "Reset" button to work.
I have included the whole of my code and would appreciate it if someone
could explain where I am going wrong.
TIA
Roger
|
by: AnnMarie |
last post by:
<script language="JavaScript" type="text/javascript">
<!--
function validate(theForm)
{
var validity = true; // assume valid
if(frmComments.name.value=='' && validity == true)
{
alert('Your full name is required. Please enter your full name!');
validity = false;
frmComments.name.focus();
|
by: Arun K |
last post by:
Hi,
I am creating a simple .aspx page to add some fields with validation.
I have used different .NET validations like REquiredFieldValidator,
RegularExpressionValidator and showed the summary in the bulleted list
on top. I have 3 text boxes, and two RadioButtonList. and 3 buttons. One
for Submit, Reset and Exit.
If submit is pressed page should be validated and submit (insert into
|
by: Nathan Sokalski |
last post by:
I have a System.Web.UI.HtmlControls.HtmlInputFile control that I use to
submit files. After the file is successfully submitted, I want the field to
be reset so that the user knows the file was submitted. However, ASP.NET
does not let you change the Value property of an HtmlInputFile control. How
can I reset the HtmlInputFile control to it's original state? Thanks.
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/
|
by: Ian Davies |
last post by:
Hello
I am struggling for a solution to clear some fields on my webpage that takes
their values from some sessions
My solution below works when the button is clicked twice. I sort of know why
I have to click it twice to do the job (the first submit resets the sessions
but this it too late to change the field values, which requires another
submit to pick up the new session values). Problem is I cant think how to
accomplish the resetting of...
| |
by: jasondavidcarr |
last post by:
Hello all,
I have a "comments" page that contains three sections; the article to
be commented on is on top, followed by previous comments, and on the
bottom a place to add new comments. It's a pretty common scenario.
I have two links from the main article page; one to view the comments
and one to add a new comment. I'm simply using <span id="top"and
<span id="bottom">, and #top or #bottom in the query string to
distinguish between...
|
by: Jay |
last post by:
I've done a search and haven't seen any consensus on how to best handle a
form reset and ASP.Net validation controls. Basically, because of the
one-form constraint in ASP.Net I've written a little JS routine to clear
form fields. Now I need to also reset any validation controls. What's the
best way to do this?
Thanks.
|
by: Kevin |
last post by:
I'm using a form where users can input a bunch of info into unbound text
controls that are used in series of calculations. At the bottom is a "reset"
button. I want to clear out all of the user inputs on the form by clicking
the button. Me.Refresh .requery .repaint do not work. Any suggestions?
|
by: AB |
last post by:
I am creating a ASP.Net 1.1 (VB) web. I have 2 drop down lists which
are independent of each other. Both are filled from a database on the
pageload. There is also a search button which searches the database
based on the 2 drop down list entries. The first entry in each drop
down list is "Please Select". What I am trying to do via client side
script is to reset the unselected drop down list when the other drop
down list selects a new...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |