SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru dale_burrell's Avatar
    Join Date
    Aug 2002
    Location
    Wellington, New Zealand
    Posts
    861
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wizards/AJAX/Panels?

    Hi All,

    I am using a Wizard, and on 1 of the steps I have a checkbox which if you check it uses some simple javascript to show another section with some additional form fields in it (this is just a straight DIV for now, but could be a panel if that does the job).

    The problem is that these additional fields have validators which is fine when they are exposed but is not fine when those fields are not exposed and therefore shouldn't be validated but are because nothing is currently turning the validators off.

    Can someone please point me to a solution to this problem, I would rather that its all done client side for speed, so I need a way to expose and enable a bunch of new form fields and their validators when the box is checked and vice versa when its unchecked again.

    Thanks in advance for your ideas.

    Cheers,

    Dale
    If you aren't living life on the edge
    - you're taking up too much space
    Creative Dreaming Ltd / Ask The Local / Amanzi Travel

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Location
    Birmingham (UK)
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Dale,

    I had a similar wizard, but I used a single panel to hide the fields and their validators - which works a treat.

    Let's say on your Wizard you have a checkbox called CheckBox1, which you check if you want a panel called Panel1 to display (or not).

    Within Panel1, you will have all your fields and their respective RequiredFieldValidators in. Let's say you have TextBox1 and TextBox2 within Panel1, as well as a RequiredFieldValidator for each one.

    Now for the properties:

    1. On CheckBox1, have AutoPostBack as True.
    2. On Panel1, Visible as False.

    Now for the coding:

    Double-Click on CheckBox1 and make sure your code is as below:

    Code:
    Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
            If CheckBox1.Checked = True Then
                Panel1.Visible = True
            Else
                Panel1.Visible = False
                TextBox1.Text = ""
                TextBox2.Text = ""
            End If
        End Sub

    In other words, if CheckBox1 is selected, then make Panel1 visible, else make it disappear.

    The reason for adding:

    TextBox1.Text = ""
    TextBox2.Text = ""

    - is so that if you do enter values for TextBox1 and TextBox2, but then change your mind by un-checking CheckBox1, then those values are reset to be blank again. This will be important if your form will enter data into a database or something.

    Hope that helps.

    Regards, Ash (UK)

  3. #3
    SitePoint Guru dale_burrell's Avatar
    Join Date
    Aug 2002
    Location
    Wellington, New Zealand
    Posts
    861
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply Ash - much appreciated. Unfortunately your solution requires a server postback which is what I am trying to avoid - sorry don't think I was clear about that. Any ideas how to do this without the server postback anyone? Thanks
    If you aren't living life on the edge
    - you're taking up too much space
    Creative Dreaming Ltd / Ask The Local / Amanzi Travel


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •