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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:55:33+00:00 2026-05-13T20:55:33+00:00

I was wondering about some best practices for data binding in web forms. For

  • 0

I was wondering about some best practices for data binding in web forms.

For example we have a control:

public partial class MyUserControl : UserControl
{
    public override void DataBind()
    {
        //#1
        base.DataBind();
        //#2
    }
}

If we wanted that control to bind its data automatically we would do something like this:

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        this.DataBind();
    }
}

In the first section of code if we do our data binding before the call to base.DataBind() (#1) then that means that, if for example we databind a ListView, we don’t have to call ListView.DataBind() because when we call base.DataBind() on our control it recursively calls DataBind on all child controls. Also, we won’t have access to any of the properties of the control that were assigned to it using the data binding code blocks <%# %>

If we do our binding on our controls after base.DataBind() (#2) then this means that DataBind is called on these controls twice. Once when base.DataBind() is called, and the second time when we are forced to call control.DataBind().

Does anyone know of some sort of pattern I can follow here that I don’t know about?

Am I making any sense here?

What am I doing wrong?

EDIT:
Looking at this page:
http://msdn.microsoft.com/en-us/library/w5e5992d.aspx

Use this method to bind data from a
source to a server control. This
method is commonly used after
retrieving a data set through a
database query. The method is
primarily used by control developers;
most controls perform data binding
automatically.

It appears that best practice is to bind controls data automatically. Databinding is for when we explicitly set a data source.

  • 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-13T20:55:34+00:00Added an answer on May 13, 2026 at 8:55 pm

    I’ve encountered problems previously, when pages become complex and you are relying on user controls binding their own data in the page load event. This has resulted in some long debugging sessions, as you can’t be guaranteed exactly when this page load event in the control will fire.

    Now, that said, these pages weren’t too well designed, and we shouldn’t have run into this problem, but I prefer to stick with the explicit and have my page tell the child controls when to do their thing – you may wish to avoid calling base.DataBind and do it explicitly instead – you may also wish to not override the DataBind method in this way and instead call the method on your control by another name.

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

Sidebar

Ask A Question

Stats

  • Questions 386k
  • Answers 386k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer .NET 3.5 didn't have new versions of mscorlib, System.dll etc… May 14, 2026 at 11:40 pm
  • Editorial Team
    Editorial Team added an answer No, it is not possible. This is because valid regular… May 14, 2026 at 11:40 pm
  • Editorial Team
    Editorial Team added an answer gnarf nailed it. I do: <link rel="stylesheet" type="text/css" media="screen" href="<?… May 14, 2026 at 11:40 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.