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 1018469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:51:43+00:00 2026-05-16T10:51:43+00:00

I have created an Address user control which is as follow: <%@ Control Language=C#

  • 0

I have created an Address user control which is as follow:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Address>" %>

   <div class="span-4" style="text-align: right" title="<%: GetLocalResourceObject("Type") %>">
        <%: GetLocalResourceObject("Type")%>
   </div>
   <div class="span-6 last">
       <%: Html.RadioButtonFor(model => model.AddressType, RealProperty.Core.Domain.AddressType.Postal, new { id = ViewData["AddressPrefix"] + "AddressType" })%>
    &nbsp;
       <%: GetLocalResourceObject("PostalType")%>
       <%: Html.RadioButtonFor(model => model.AddressType, RealProperty.Core.Domain.AddressType.Intersection, new { id = ViewData["AddressPrefix"] + "AddressType" })%>
    &nbsp;
       <%: GetLocalResourceObject("IntersectionType")%>
    </div>
    <div class="span-4" style="text-align: right" title="<%: GetLocalResourceObject("Country") %>">
      <%: GetLocalResourceObject("Country")%>
    </div>
    <div class="span-6 last">
    <%: Html.DropDownList(ViewData["AddressPrefix"] + "Country", new SelectList(RealProperty.Core.Service.CountryService.Countries, "Id", "Name"), "Please select Country", new { id = ViewData["AddressPrefix"] + "Country" })%>
        <%: Html.ValidationMessage(ViewData["AddressPrefix"] + "Country")%>
    </div>
    <div class="span-4" style="text-align: right" title="<%: GetLocalResourceObject("Address1") %>">
       <%: GetLocalResourceObject("Address1")%>
    </div>

 .
 .
 .
 .

I’ll be using two instance of this user control on a page for “Main Address” and “Alternate Address”:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PhysicalLocation>" %>

   <div class="span-12">
        <fieldset>
            <legend>Main Address</legend>
            <%
                Html.RenderPartial("~/Views/Address/New.ascx", Model.MainAddress);
            %>
        </fieldset>
    </div>
    <div class="span-12 last">
        <fieldset>
            <legend>Alternate Address</legend>
            <%
                Html.RenderPartial("~/Views/Address/New.ascx", Model.AlternateAddress);
            %>
        </fieldset>
    </div>

Address user control is bound to “Address” model.

 [PostalCode("PostalCode", "Country", ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "PostalCode_Is_Invalid"), DisplayName("Address") ]
    public class Address : ICanBeValidated
    {

        public virtual long Id { get; set; }

        [RegularExpression("^[^,'\"]*$", ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "InvalidCharacter"),
    Required(ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "Field_Required"), StringLength(255, ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "Field_Max_Length_Allowed")]
        public virtual string Address1 { get; set; }

        [RegularExpression("^[^,'\"]*$", ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "InvalidCharacter"),
    StringLength(255, ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "Field_Max_Length_Allowed")]
        public virtual string Address2 { get; set; }

        [RegularExpression("^([a-zA-Z\\.\\-\\s]*)$", ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "ValidCharacter_Allowed")]
        [Required(ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "Field_Required"), StringLength(30, ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "Field_Max_Length_Allowed")]
        public virtual string City { get; set; }
    .
    .
    .
 }

I expect upon render, it creates two differnet sets of input controls for MainAddress and AlternateAddress (i.e. coming from Web Form experience).

I’m guessing that I’m missing a very basic point here, since when both user controls are rendered, on the page I have two “city”,”address1″, “address2”, etc.

And as the result Microsoft Validation only works for one of the user controls. The JSON array that is sent to client only contains the validation for one, base on the Model definition. For example for “City” property of the address we have only one entry in the mentioned array and as the result only the “span” element with id “City_ValidateMessage” associated to validation exists.

I appreciate any thoughts.

Thanks,
Mohammad

  • 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-05-16T10:51:44+00:00Added an answer on May 16, 2026 at 10:51 am

    The solution that I found on Steve Sanderson’s blog is a hack on HttpContext to generate unique ids when rendering the user control. It solves the problem with validation nicely.

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

Sidebar

Related Questions

I have created a piece of code which takes an IP address (from main
I have an address control which display the contact info of the person. so
A user logins into the SharePoint site we have created using their email address
I have created one web app using mvc and in that used form authentication
I currently have a user control that is used on both an /Address/Edit and
I have two models: Person and Address which I'd like to create in a
I have created some JQuery that will expand a div 'popup' on hover and
Linux Server Box running WebSphere MQ Server v7.1: I have created a user 'mq-user'
I have created a form where the user can search the database, and the
I have created a list of contact's in user phone, now i want to

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.