Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8142205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:44:19+00:00 2026-06-06T12:44:19+00:00

I have an ASP.NET usercontrol that implements the ValidationProperty attribute. This attribute successfully makes

  • 0

I have an ASP.NET usercontrol that implements the ValidationProperty attribute. This attribute successfully makes it possible for me to use a RequiredFieldValidator for my custom control, however on validation it causes a full postback rather than using client side javascript based validation.

Is there a way to prevent this and enable client side validation without using a custom validator?

This is the what my UserControl looks like.

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ucBooleanRadio.ascx.cs" Inherits="MyCompany.Web.UserControls.ucBooleanRadio" %>

<div class="BooleanRadio">
    <input runat="server" id="radTrue" type="radio" name="BooleanRadio" value="True" /> Yes
    <input runat="server" id="radFalse" type="radio" name="BooleanRadio" value="False" /> No
</div>

[ValidationProperty("Checked")]
public partial class ucBooleanRadio : System.Web.UI.UserControl
{
    public Nullable<bool> Checked
    {
        get
        {
            if (radTrue.Checked || radFalse.Checked)
                return radTrue.Checked;
            else
                return null;
        }
        set
        {
            radTrue.Checked = value != null ? value.Value : false;
            radFalse.Checked = value != null ? !value.Value : false;                    
        }
    }
}

And this is how it is being used

<uc1:ucBooleanRadio ID="ucAgree" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" CssClass="Validator" Display="Dynamic" ControlToValidate="ucAgree" InitialValue="" ErrorMessage="You must agree to continue."></asp:RequiredFieldValidator>

Page.Validate();
if (Page.IsValid)
{
    //Do stuff
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:44:21+00:00Added an answer on June 6, 2026 at 12:44 pm

    Turns out, ASP.NET don’t event care about element tag.
    I’ve just looked through validation code and found this

    function ValidatorGetValue(id) {
        var control;
        control = document.getElementById(id);
        if (typeof(control.value) == "string") {
            return control.value;
        }
        return ValidatorGetValueRecursive(control);
    }
    

    So

    <div class="BooleanRadio" id="<%= ClientID %>" value="<%= radTrue.Checked? "true" : radFalse.Checked? "false" : "" %>">
        <% radTrue.Attributes["onclick"] = "document.getElementById('" + ClientID + "').value='true'"; %>
        <% radFalse.Attributes["onclick"] = "document.getElementById('" + ClientID + "').value='false'"; %>
        <input runat="server" id="radTrue" type="radio" name="BooleanRadio" value="True" /> Yes
        <input runat="server" id="radFalse" type="radio" name="BooleanRadio" value="False" /> No
    </div>
    

    actually works :\, as does

    <div class="BooleanRadio" id="<%= ClientID %>">
        <input runat="server" id="radTrue" type="radio" name="BooleanRadio" value="True" /> Yes
        <input runat="server" id="radFalse" type="radio" name="BooleanRadio" value="False" /> No
    </div>
    

    And there is events autohooking – validated element (one with ClientID) and its children are wired to cause validation automatically (look ValidatorHookupControl).
    That may result in:
    1. user does something
    2. validation is performed
    3. value to validate is updated (after validation!)
    First example with value on div behaves this way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a partial view (UserControl) that implements a simple pager in my Asp.Net
I have a usercontrol in ASP.Net featuring a button that I use to postback.
I have asp.net usercontrol that is including some js script like this <script type=text/javascript
Is it possible in asp.net that for a custom control (that extends UserControl) to
I have an ASP.Net UserControl that looks like this: <%@ Control Language=C# AutoEventWireup=true CodeBehind=WebUserControl1.ascx.cs
I have a usercontrol that is in an asp.net page that contains a button.
I have an ASP.Net application that has a UserControl that needs to be rendered
I have an asp.net usercontrol that contains a jQuery UI Dialog Control. All works
I have a for which is built within an ASP.net usercontrol. This form is
I have an asp.net usercontrol (ascx) that inherits from an abstract class (that inherits

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.