Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Is it possible to have a required field validator for Taxonomy webtagging control. I tried using standard Required field validator but it fails. Is there any property in taxonomy webtagging control.??

share|improve this question

4 Answers 4

var value = $("#<%=TaxonamyControlID.ClientID %>").find("input[type='hidden']").val()

if(value == '') 
{ 
    alert('please enter a value') ; return false; 
} 
else 
{
    return true;
}
share|improve this answer

I think Required Field Validator that comes out of the box will not work with Taxonomy web tagging control because the tagging control which appears like a text box (input type=text) is NOT an input control when it renders in browser.

You can use CustomValidator though as shown in article below:

http://asp.net-tutorials.com/validation/custom-validator/

At server side you can check Text Property of control and if its empty, set e.IsValid = false.

share|improve this answer

Actual value of the taxonomy input field is stored in a hidden input field.

If Javascript is OK for you, and you can surround your taxonomy control with DIV ID myTaxDiv, you can get the value quite easily. I've used this jQuery command:

j("#myTaxDiv > span > span > input[type='hidden']").val("");

share|improve this answer

I've been able to successfully validate a TaxonomyWebTaggingControl using a CustomValidator as shown below. In my case the taxonomy field is not required but I wanted to make sure the user entered a valid value. In your case you could update the event handler to check if the user entered a value and set the ErrorMessage appropriately.

Be sure NOT to set the ControlToValidate property of the CustomValidator or you will get an error.

In your ASPX page

<Taxonomy:TaxonomyWebTaggingControl ID="region" runat="server"></Taxonomy:TaxonomyWebTaggingControl><br />
<asp:CustomValidator ID="regionValidator" runat="server" Display="Dynamic" OnServerValidate="regionValidator_ServerValidate"></asp:CustomValidator>

In your code behind

protected void regionValidator_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
        string reason;
        if (!region.Validate(out reason))
        {
            args.IsValid = false;
            regionValidator.ErrorMessage = reason;
        }
    }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.