Solved

RequiredFieldValidator for an optional field

Posted on 2013-01-11
2
278 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 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

22 Experts available now in Live!

Get 1:1 Help Now