Solved

clear button - vb2005

Posted on 2006-07-11
3
248 Views
Last Modified: 2010-08-05
 I have RequiredFieldValidator on these four textboxes. The code  does not work right. Please help. When I click clear button, some of the required field show right next to the textboxes.  

Protected Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click

        Me.TextBox1.Text = Nothing
        Me.TextBox2.Text = Nothing
        Me.TextBox3.Text = Nothing
        Me.TextBox4.Text = Nothing

    End Sub
0
Comment
Question by:VBdotnet2005
3 Comments
 

Author Comment

by:VBdotnet2005
ID: 17087880
Set the property "causesvalidation" of that button to false? What else can you do it beside this?
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 17088174
I'm not sure why you don't want to use CausesValidation, but you can do it another way.

If you disable the client-side validation on your validator control then you could also disable/re-enable it manually on the individual validator controls at the server-side (if, for example, you wanted to disable some validators but leave others active -- for some reason):

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

   Me.RequiredFieldValidator1.Enabled = False
   Me.TextBox1.Text = ""
   Me.RequiredFieldValidator1.Enabled = True

End Sub


Here's a sample without code-behind.  The one button turns off the validation before it makes the change.  The other doesn't.

sample.aspx
--------------
<%@ Page Language="vb"  %>
<script language="vb" runat="server">

    Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.RequiredFieldValidator1.Enabled = False
        Me.TextBox1.Text = ""
        Me.RequiredFieldValidator1.Enabled = True
    End Sub

    Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.TextBox1.Text = ""
    End Sub
   

</script>

<HTML>
     <body>
          <form id="Form1" method="post" runat="server">
               <P>
                    <asp:Button id="Button1" runat="server" onclick="Button1_Click" Text="Validator Disabled"></asp:Button>&nbsp;
                    <asp:Button id="Button2" runat="server" onclick="Button2_Click" Text="Validator Enabled"></asp:Button></P>
               <P>
                    <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator"
                         ControlToValidate="TextBox1" EnableClientScript="False"></asp:RequiredFieldValidator></P>
          </form>
     </body>
</HTML>

0
 
LVL 27

Accepted Solution

by:
Sammy earned 250 total points
ID: 17088286
actually you cant reset the controls due to viewstate preserving the values.
the only way to clear the values is by using a client script

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.btnClear.Attributes.Add("onclick", "location.href= location.href; return false")
    End Sub

This will redirect the page to itself without any posting and it will work with any browser.

HTH
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
grab and show facebook pages event calendars 6 65
Multiple file Upload asp.net 2 40
Execute Stored Procedure for a set of values 5 44
Reset asp.net login password 4 31
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 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

16 Experts available now in Live!

Get 1:1 Help Now