[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

ASP.NET  CLEAR RESET BUTTON

Posted on 2004-04-11
8
Medium Priority
?
4,763 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Technology Partners: 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!

Question has a verified solution.

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

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…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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 video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

649 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