Solved

clear button - vb2005

Posted on 2006-07-11
3
252 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 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

707 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