When I Postback The Page, My Repeater.Items.Count = 0

Mar 13, 2009 at 2:06 PM
I used http://www.pnpguidance.net/Screencast/UnityAspWebDependencyInjectionGuestsAutofacNinject.aspx  Code!

When I Postback The Page, My Repeater.Items.Count = 0 , Why ?


my code:
---------------------------------------------default.aspx-------------------------------------------

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

        void Bind()
        {
            rptItems.DataSource = new string[] { "A", "B", "C" };
            rptItems.DataBind();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            ((Button)sender).Text = rptItems.Items.Count.ToString();
        }

--------------------------------------UnityHttpModule-----------------------------------------

    public class UnityHttpModule : IHttpModule
    {
        private HttpApplication _application;

        #region IHttpModule Members

        public void Dispose()
        {
            throw new NotImplementedException();
        }

        public void Init(HttpApplication context)
        {
            _application = context;
            _application.PreRequestHandlerExecute += OnPreRequestHandlerExecute;
        }

        void OnPreRequestHandlerExecute(object sender, EventArgs e)
        {
            Page page = _application.Context.CurrentHandler as Page;

            if (page != null)
            {
                IoC.Inject(page.GetType(), page);

                page.InitComplete += (src, args) => InjectUserControls(page);
            }
        }

        private void InjectUserControls(Control parent)
        {
            if (parent.Controls.Count > 0)
            {
                foreach (Control control in parent.Controls)
                {
                    if (control is UserControl)
                        IoC.Inject(control.GetType(), control);

                    InjectUserControls(control);                   //if comment out this line,Repeater.Items.Count = 3, What Wrong with this line ?

                }
            }
        }

        #endregion
    }

---------------------------------------------------------------------------------

Mar 13, 2009 at 6:57 PM
You'll need to ask the author of that code - despite his deliberate attempts to make it look like it is, pnpguidance.net is NOT a Microsoft site and is not part of patterns & practices.

Mar 14, 2009 at 2:04 AM
thinks
Mar 15, 2009 at 4:19 AM
I find a phenomena,
if I change EventHandler
page.ProLoad += (src, args) => InjectUserControls(page);
Everythings All Right

Who Can Tell Me Why?