?
Solved

clear button - vb2005

Posted on 2006-07-11
3
Medium Priority
?
254 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
[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
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 Ageil earned 1000 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

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
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 …
Suggested Courses

770 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