?
Solved

RequiredFieldValidator for an optional field

Posted on 2013-01-11
2
Medium Priority
?
285 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
[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
2 Comments
 
LVL 25

Accepted Solution

by:
Rouchie earned 750 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 750 total points
ID: 38767021
You need to use the ValidatorEnable javascript API to enable disable the  validator according to your requirement.
0

Featured Post

Not sure which OpenStack Certification to get?

So you’ve realized you might want to get certified in OpenStack, but you’re not sure what the benefits might be or even which one you should take. You know there are several certification courses you can choose from, but how do you know which one is right for you?

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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.…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

777 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