One more thing I'd like to clarify. I really don't care the value of
Repeater.Controls.Count. The function I wrote exhausting the controls tree
by traversing all the child controls recursively by a given control, and
creating literal controls programmatically. I need Controls.Count for
finding child controls inside the placeholder, panel and user control, but
not repeater. If a repeater is a part of the control tree of the control I
passed into the my function, that repeater's viewstate will be gone during
the postback, which doesn't make any sense to me.
ILN
"Invalidlastname" <invalidlastname@toomanyvalidations.page> wrote in message
news:un5Liee2DHA.2360@TK2MSFTNGP10.phx.gbl...[color=blue]
> Steven,
> I think you are misunderstanding my question. I AM NOT TRYING TO ACCESS[/color]
THE[color=blue]
> VIEWSTATE in OnInit EVENT.
>
> What I observed was if a repeater Controls.Count was called before the
> loadviewstate, in my case will be in OnInit, then that repeater won't be
> able to restore it's items from the viewstate. The postback page will[/color]
render[color=blue]
> an empty repeater since there is no repeater items.
>
> In my attached example, I used a repeater to bind an array, and the
> databinding was called when page is not postback. I have an asp button[/color]
with[color=blue]
> server-side click event. When the button was click, if the repeater
> Controls.Count was called in the OnInit, then the page gets a empty
> repeater, which means the repeater's viewstate was lost during the
> loadviewstate. If you remove the line of calling repeater's Controls.Count
> in the Page.OnInit, then repeater's viewstate will be restored and[/color]
rendered[color=blue]
> properly.
>
> PLEASE run the attached example yourself, or create your own testing page,
> just see the difference if you call Repeater Controls.Count in the OnInit.
> This is a very simple example, which only demonstrate one thing: "the
> repeater can not be rendered properly in the postback page if[/color]
Controls.Count[color=blue]
> was called in the OnInit"
>
> As I explained in my previous post, I am not trying to access viewstate in
> OnInit. The reason I called the Controls.Count is because I add certain
> literal controls programmatically, and I need to reconstruct the control
> tree before the loadviewstate was called. That's the reason I have my
> method, which relies on the value of Controls.Count, called in the OnInit,
> to make sure it occurred before the loadviewstate.
>
> Thanks,
>
> ILN
>
>
>
>
> "Steven Cheng[MSFT]" <v-schang@online.microsoft.com> wrote in message
> news:0BzIkLY2DHA.2184@cpmsftngxa07.phx.gbl...[color=green]
> > Hi Invalidlastname,
> >
> >
> > Thank you for using Microsoft Newsgroup Service. Based on your[/color]
> description,[color=green]
> > you're dealing with an ASP.NET web application. In one page, you add[/color][/color]
some[color=blue][color=green]
> > code to retrieve a Repeater control's "Controls.Count" member and
> > encountered the error which indicates the ViewState isn't avaliable.[/color]
> Please[color=green]
> > correct me if my understanding of your problem is not quite exact.
> >
> > As for the situation you described, I think it is because the page's
> > viewstate hasn't been loaded when the Page's "Init" event is fired. In
> > ASP.NET the Page class has serveral buildin events, they are:
> > "Init", "LoadViewState", "LoadPostData", "Load",
> > "RaisePostDataChangedEvent", "RaisePostBackEvent", "PreRender",
> > "SaveViewState", "Render" , "Unload",
> > Also, their called sequence is as above. So in the Page's init event,[/color][/color]
the[color=blue][color=green]
> > page's ViewState hasn't been loaded yet, also its whole structure(such[/color][/color]
as[color=blue][color=green]
> > sub controls hierarchy) hasn't been constructed completely. If you try
> > accessing the viewstate at that time, you'll find it invalid. So I[/color][/color]
suggest[color=blue][color=green]
> > that you try implementing the operation in the Page's "Load" event.
> > For the detailed information on the ASP.NET page's event model and[/color][/color]
object[color=blue][color=green]
> > model and lifecycle(the same as a web server control), here is some tech
> > articles in MSDN:
> >
> > #Page Life Cycle
> >[/color]
>[/color]
http://msdn.microsoft.com/library/en...msPageProcessi[color=blue][color=green]
> > ngStages.asp?frame=true
> >
> > #Page Object Model
> >[/color]
>[/color]
http://msdn.microsoft.com/library/en...eobjectmodel.a[color=blue][color=green]
> > sp?frame=true
> >
> > #ASP.NET Server Controls' Life Cycle
> >[/color]
>[/color]
http://msdn.microsoft.com/library/en...rolexecutionli[color=blue][color=green]
> > fecycle.asp?frame=true
> >
> >
> > Please check out the preceding suggestions. If you have any questions,
> > please feel free to post here.
> >
> >
> > Steven Cheng
> > Microsoft Online Support
> >
> > Get Secure!
www.microsoft.com/security
> > (This posting is provided "AS IS", with no warranties, and confers no
> > rights.)
> >
> >[/color]
>
>
>[/color]