Solved

ASP.NET  CLEAR RESET BUTTON

Posted on 2004-04-11
8
4,736 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
Gigs: Get Your Project Delivered by an Expert

Select from 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.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSIS 2010 Convert to SSIS 2013 On Different Box 3 58
String manipulation in Visual Basic 7 62
Need more details 5 148
Writing comments on <p></P> or paragraph 2 10
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

785 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