Solved

ASP.NET  CLEAR RESET BUTTON

Posted on 2004-04-11
8
4,745 Views
Last Modified: 2013-11-25
I am new to ASP.NET, developing a simple contact us form.

The problem in which I am having is how to code a simple clear/reset button in asp.net. With asp you can utilise the simple form clear button - however with  asp.net it is proving difficult!

Below is a simple code extract from the form I am developing (COULD SOMEONE PLEASE GIVE ME AN EXAMPLE ON HOW TO CODE THE CLEAR/RESET BUTTON ON A SIMPLE TEXT FIELD IN ASP.NET

<form runat="server">
<h2>Enquiry Form </h2>
<p><b class="table">Your Name:</b>
<asp:TextBox ID="txtName" runat="server" />      
<asp:Button ID="Clear" runat="server" CommandName="Clear" Text="Clear Form" />        
 <asp:Button runat="server" ID="btnSendFeedback" Text="Send Form"  
</form>
0
Comment
Question by:SamFletcher55
8 Comments
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10800664
did you try

<input type=reset runat=server>
<input type=submit runat=server>
0
 

Author Comment

by:SamFletcher55
ID: 10800761
Yes I have tried that - it works initially but when clicking the submit button and tyhe validator returns an error (e.g no a proper email) the reset button no longer works!

Is there any way to sort this problem?
0
 
LVL 12

Expert Comment

by:monosodiumg
ID: 10801482
In the postback when the user clicks reset button, clear your field(s):

txtName.value = ""
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:SamFletcher55
ID: 10801768
could you give me an example on how to do this please?
0
 
LVL 12

Accepted Solution

by:
monosodiumg earned 45 total points
ID: 10801863
This code goes in your ASP.NET page:

Private Sub Button1_Click(....)
  Me.txtName.text= "" 
End Sub

(don't know the name of your button etc)
0
 

Author Comment

by:SamFletcher55
ID: 10802007
Yes that works! however this causes another problem  - (the validation errors still appear when you click the clear button)

Is there any way of clearing the validation errors at the same time as clearing the text fields?

THE CLEAR/RESET BUTTON CODE:

Sub btnClear_Click(sender as Object, e as EventArgs)
    txtName.Text = ""
    txtEmail.Text = ""
    txtMessage.Text = ""
End Sub

THE VALIDATION CODE:

<asp:RegularExpressionValidator ID="emailRegexVal"
            ControlToValidate="txtEmail"
            ErrorMessage="Email. "
            Display="Dynamic"
            ValidationExpression="^[\w-]+@[\w-]+\.(com|net|org|edu|mil|co.uk|co.im)$"
            Font-Name="Arial" Font-Size="8"
            runat=server> * Please enter a valid email address.
    </asp:RegularExpressionValidator>
0
 

Author Comment

by:SamFletcher55
ID: 10802026
monosodiumg if you can sort the above I will award you all the points!

Kind regards
0
 
LVL 26

Assisted Solution

by:Rejojohny
Rejojohny earned 80 total points
ID: 10804036
if ur clear buton is as web control and not an HTML control, then set the property "causesvalidation" of that button to false ..

BTW, i canot really uinderstand the situation where u r facing the problem . if ur clear button is HTML conmtrol as suggested by venkateshwarr, then the validation would only happen when u try to move focus from the "txtEmail" contro with an invalid email adress . this should be fine na ..
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

730 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