Solved

ASP.NET  CLEAR RESET BUTTON

Posted on 2004-04-11
8
4,726 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
Comment Utility
did you try

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

Author Comment

by:SamFletcher55
Comment Utility
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
Comment Utility
In the postback when the user clicks reset button, clear your field(s):

txtName.value = ""
0
 

Author Comment

by:SamFletcher55
Comment Utility
could you give me an example on how to do this please?
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 12

Accepted Solution

by:
monosodiumg earned 45 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now