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

  • Home
  • SEARCH
  • 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 906659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:25:25+00:00 2026-05-15T16:25:25+00:00

Working on an ASP.NET 4.0 project, which uses user controls to dynamically generate a

  • 0

Working on an ASP.NET 4.0 project, which uses user controls to dynamically generate a form based on definitions stored in the database. One form field would look like this:

<usc:RefControl ID="ctrlUser1" 
    ReferenceFieldId='product.user1' 
    ValidationFormat="^\d+\.?\d{0,2}$"
    runat="server"/>

Behind the scenes the control emits a RegularExpressionValidator based on the RefControl.ValidationFormat property.

This works fine, however the problem is that this architecture only allows us to validate with regexes. Now I need to add date format validation, based on the user’s preferences (which aren’t dependent on their UICulture).

Reluctant to refactor the entire user control setup, I need to be able to pass a on-the-fly regex pattern to the ValidationFormat property. Currently I’m using a data binding expression to bind the property to a page instance method:

<usc:RefControl ID="ctrlUser2" 
    ReferenceFieldId='product.user2' 
    ValidationFormat="<%# GetUserDateValidationFormat()%>" 
    runat="server"/> 

Code behind:

/// <summary>
/// Returns a regular expression that validates the current user's date format
/// </summary>
public string GetUserDateValidationFormat() 
{
    //...
}

Works okay on first page load, but on subsequent postbacks the validation doesn’t work. I think the issue is that the data binding expression doesn’t evaluate at all, but I’m not sure I understand why. I’m calling Page.DataBind() in Page_Init whether Page.IsPostBack or not, so shouldn’t this work?

If you see I’m barking up the wrong tree, any alternative solutions to the same problem are also welcome.

EDIT

Managed to solve this problem. The issue was with the way ASP.NET page life cycle invokes the user control’s events before the page’s own events. The control values were being initialized before the data binding on the page could happen.

Because I still need to do the control initialization before Page_Load to subscribe the controls to viewstate, I simply moved the initialization logic to the Page.InitComplete event so the call to Page.DataBind() could get called first.

    protected void Page_Init(object sender, EventArgs e)
    {
        Page.InitComplete += new EventHandler(Page_InitComplete);
    }

So the event tree becomes

  1. User Control Page_Init => Hook InitComplete handler
  2. Page (aspx) Page_Init => Bind data
  3. User Control Page_InitComplete => Initialize the control
  • 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-15T16:25:26+00:00Added an answer on May 15, 2026 at 4:25 pm

    Couldn’t you just set the property in Page_Load()?

    public void Page_Load(...)
    {
        ctrlUser1.ValidationFormat = GetUserDateValidationFormat();
        // do whatever stuff you do
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.