Solved

RequiredFieldValidator for an optional field

Posted on 2013-01-11
2
280 Views
Last Modified: 2013-01-16
Hi,

Please find the attached file.

If i select Add New radio button, RadEditor control will be displayed.If I select Link to existing radio button, URL field will be displayed. If user select Add New then RadEditor is a mandatory field. If user select Link to Existing then URL field is the mandatory field. How to check this?

I put 2 RequiredFieldValidator controls and by default i make it enabled = false then on click of submit button i enabled as below but it is not working:

  protected void btnSubmit_Click(object sender, EventArgs arg)
        {
            if (radioAddNew.Checked)
                RequiredFieldValidatorRadEditorContent.Enabled = true;
            else if (radioLinkToExisting.Checked)
                RequiredFieldValidatorURL.Enabled = true;

            if (Page.IsValid)
            {
                  //other code
      }
      }

Any other way to do this?


Thanks,
Requiredfieldvalidator.jpg
0
Comment
Question by:swathi111
2 Comments
 
LVL 25

Accepted Solution

by:
Rouchie earned 250 total points
ID: 38766507
>>  If user select Add New then RadEditor is a mandatory field. If user select Link to Existing then URL field is the mandatory field. How to check this?


The RequiredFieldValidator is active as soon as it appears on-screen.  So you need to make it invisible in advance.  From your description I would set MyRequiredFieldValidator.Visible = False when the user clicks Link to Existing and then show it if the user clicks Add New.

Protected Void AddNewClicked(object sender, eventargs e) handles AddNew.Clicked
{
RequiredFieldValidator.Visible = False
}

Open in new window

0
 
LVL 20

Assisted Solution

by:informaniac
informaniac earned 250 total points
ID: 38767021
You need to use the ValidatorEnable javascript API to enable disable the  validator according to your requirement.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

867 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

15 Experts available now in Live!

Get 1:1 Help Now