West Wind Toolkit for .NET
ASPX txtField not binding on startup.
Gravatar is a globally recognized avatar based on your email address. ASPX txtField not binding on startup.
  Craig Tucker
  All
  Apr 2, 2020 @ 02:31pm

Hi Rick, I am trying to use the asp.net toolkit binding controls fo error handling on an aspx page.

After the page loads there is a red exclamation mark next to the first name field indicating the error "Unable to bind profile.FirstName (First Name)". After the page loads, the validation seems to work.

<ww:DataBinder ID="DataBinder" runat="server">
    <DataBindingItems>
        <ww:DataBindingItem runat="server" BindingSource="profile" BindingSourceMember="FirstName"
            ControlId="txtFirstName" IsRequired="True" UserFieldName="First Name">
        </ww:DataBindingItem>
    </DataBindingItems>
</ww:DataBinder>
 protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)
            {
                Page.Validate();
                if (Page.IsValid)
                {
                    DataBinder.DataBind();
                }
            }

The only error I could find stepping through the code is "Page.IsValid cannot be called before validation has taken place. It should be queried in the event handler for a control that has CausesValidation=True and initiated the postback, or after a call to Page.Validate."

Can you please assist?

Thanks, Craig

Gravatar is a globally recognized avatar based on your email address. re: ASPX txtField not binding on startup.
  Rick Strahl
  Craig Tucker
  Apr 2, 2020 @ 04:26pm

That's a binding error. Make sure that profile is public and a property of the container, and that FirstName is a public property.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: ASPX txtField not binding on startup.
  Craig Tucker
  Rick Strahl
  Apr 3, 2020 @ 07:38am

Hi Rick, The profile and FirstName are both public, however I am not sure how to tell if profile is a property of the container. I guess that has to be it, please help.

I meant to mention I am trying to do this within a usercontrol ascx page. Thanks, Craig

Gravatar is a globally recognized avatar based on your email address. re: ASPX txtField not binding on startup.
  Rick Strahl
  Craig Tucker
  Apr 3, 2020 @ 03:53pm

Make sure profile is a property not a field and so is First Name. Are other properties binding or is it just that one? Also make sure there aren't multiple bindings to the same control.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: ASPX txtField not binding on startup.
  Craig Tucker
  Rick Strahl
  Apr 6, 2020 @ 12:28pm

Hi Rick, I think I found the issue. After successfully binding to a public test variable, I knew it had to be with the profile object, however it was defined public along with the FirstName (etc) fields. However, the profile class was not marked [System.Serializable] which was the epiphany moment. I really like working with the West-Wind .NET controls. Thanks for your help!

Gravatar is a globally recognized avatar based on your email address. re: ASPX txtField not binding on startup.
  Rick Strahl
  Craig Tucker
  Apr 6, 2020 @ 12:42pm

the profile class was not marked [System.Serializable]

That should not be necessary - there's nothing in the binding framework that serializes data.

+++ Rick ---

© 1996-2024