?
Solved

ASP.NET  CLEAR RESET BUTTON

Posted on 2004-04-11
8
Medium Priority
?
4,771 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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 180 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 320 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

864 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