Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Repeater DataBinding on PostBack and base.DataBind()

Reply
Thread Tools

Repeater DataBinding on PostBack and base.DataBind()

 
 
Oleg
Guest
Posts: n/a
 
      09-25-2009
Hi,

Can anyone please clarify why Repeater does not maintain its viewstate when
the base.DataBind() call is made on Page_Load.
Example that illustrates this problem is here:

1. protected void Page_Load(object sender, EventArgs e) {
2.
3. base.DataBind();
4.
5. if (!IsPostBack) {
6. string[] source = new string[] { "1", "2", "3" };
7. ddlTest.DataSource = source;
8. ddlTest.DataBind();
9.
10. rptTest.DataSource = source;
11. rptTest.DataBind();
12.
13. }
14.
15. }


When the page goes through the postabck DropDownList maintain its state, but
repeater is not.
Removing base.DataBind(); on line 3 solves the problem.

Why is this difference between the DropDownList and Repeater?

Does this problem means that Repeater needs to be DataBound on both PostBack
and !Postback ?

The only reason I have base.DataBind() on the page is to void this error
"The Controls collection cannot be modified because the control contains
code blocks (i.e. <% ... %>)"
This is because I have following validation code on aspx page

1. var ddl = document.forms[0].<%#ddlTest.ClientID%>;

Thanks in advance,
Oleg
 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      09-25-2009
the repeater needs to be data bound on postback. as postback data is
applied before page load, the databind should be done in oninit. to do
the databind itself on postback, the repeater would need to store the
datasource in viewstate (a hidden field on the form) via serialization.
this is too heavy a load.

the dropdown list usually is smaller, and storing a copy of the list in
a hidden field is not too expensive, but you are a better of disabling
viewstate and loading it in oninit to make the page size smaller.

-- bruce (sqlwork.com)




Oleg wrote:
> Hi,
>
> Can anyone please clarify why Repeater does not maintain its viewstate when
> the base.DataBind() call is made on Page_Load.
> Example that illustrates this problem is here:
>
> 1. protected void Page_Load(object sender, EventArgs e) {
> 2.
> 3. base.DataBind();
> 4.
> 5. if (!IsPostBack) {
> 6. string[] source = new string[] { "1", "2", "3" };
> 7. ddlTest.DataSource = source;
> 8. ddlTest.DataBind();
> 9.
> 10. rptTest.DataSource = source;
> 11. rptTest.DataBind();
> 12.
> 13. }
> 14.
> 15. }
>
>
> When the page goes through the postabck DropDownList maintain its state, but
> repeater is not.
> Removing base.DataBind(); on line 3 solves the problem.
>
> Why is this difference between the DropDownList and Repeater?
>
> Does this problem means that Repeater needs to be DataBound on both PostBack
> and !Postback ?
>
> The only reason I have base.DataBind() on the page is to void this error
> "The Controls collection cannot be modified because the control contains
> code blocks (i.e. <% ... %>)"
> This is because I have following validation code on aspx page
>
> 1. var ddl = document.forms[0].<%#ddlTest.ClientID%>;
>
> Thanks in advance,
> Oleg

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Databinding expressions are only supported on objects that have a DataBinding event jobs ASP .Net 0 09-25-2007 11:54 PM
Postback and databinding question Froefel ASP .Net 1 08-30-2007 02:07 PM
Gridview encoding, or how to run commands before gridview's default databinding, or, how do I disable default databinding at all? Sergei Shelukhin ASP .Net 1 11-12-2006 01:43 PM
repeater and databinding (postback) tarscher@gmail.com ASP .Net 1 10-11-2006 11:39 AM
DataGrid Custom Column Error when DataBinding "does not contain a definition for 'DataBinding'" Earl Teigrob ASP .Net Datagrid Control 1 03-01-2004 04:52 AM



Advertisments