[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

RequiredFieldValidator for an optional field

Posted on 2013-01-11
2
Medium Priority
?
286 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

656 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