473,385 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

CompositeDataBoundControl doesn't retreive it's state information.

I have a control derived from ComposeteDataBoundControl. Control doesn't
retreive it's state information. I am going to frick out! What should I do
more?
I added two codes. One is for Default.aspx to Test the control
"SampleDataBound". When I click to the "Refresh" button here, the data
displayed in the SampleDataBound control become lost.

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

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server" type="text/C#">
protected override void OnLoad(EventArgs e)

{

base.OnLoad(e);

if (!Page.IsPostBack)

{

System.Collections.Generic.List<stringlist = new
System.Collections.Generic.List<string>();

list.Add("UMUT");

list.Add("Mehmet");

list.Add("Hasan");

this.d.DataSource = list;

this.d.DataBind();

}

}

</script>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<Test:SampleDataBound runat="server" ID="d" EnableViewState="true" />

</div>

<asp:Button runat="server" ID="btn" Text="Refresh" />

</form>

</body>

</html>

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

public class SampleDataBound : CompositeDataBoundControl, INamingContainer

{

private Table table;

protected override int
CreateChildControls(System.Collections.IEnumerable dataSource, bool
dataBinding)

{

System.Collections.IEnumerator e = dataSource.GetEnumerator();

table = new Table();

this.Controls.Add(table);

TableRow row = null;

TableCell cell = null;

int count = 0;

while (e.MoveNext())

{

row = new TableRow();

cell = new TableCell();

if (dataBinding)

{

cell.Text = e.Current.ToString();

}

row.Cells.Add(cell);

table.Rows.Add(row);

count++;

}

return count;

}

}


Jul 5 '06 #1
2 1348
Hi,

you have lines

row = new TableRow();
cell = new TableCell();
if (dataBinding)
{
cell.Text = e.Current.ToString();
}
row.Cells.Add(cell);
table.Rows.Add(row);

put them in different order

row = new TableRow();
table.Rows.Add(row);
cell = new TableCell();
row.Cells.Add(cell);

if (dataBinding)
{
cell.Text = e.Current.ToString();
}

e.g do databinding after cell is added to the Rows and so on.

Reason is that a ontrol like TableCell starts its lifecycle when it's added
to the Controls collection (even though here it's to Cells, but that's
basically just abstraction) and part of this lifecycle is to start tracking
state.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"Umut Tezduyar" <ut*******@gmail.comwrote in message
news:OG*************@TK2MSFTNGP04.phx.gbl...
>I have a control derived from ComposeteDataBoundControl. Control doesn't
retreive it's state information. I am going to frick out! What should I do
more?
I added two codes. One is for Default.aspx to Test the control
"SampleDataBound". When I click to the "Refresh" button here, the data
displayed in the SampleDataBound control become lost.

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

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server" type="text/C#">
protected override void OnLoad(EventArgs e)

{

base.OnLoad(e);

if (!Page.IsPostBack)

{

System.Collections.Generic.List<stringlist = new
System.Collections.Generic.List<string>();

list.Add("UMUT");

list.Add("Mehmet");

list.Add("Hasan");

this.d.DataSource = list;

this.d.DataBind();

}

}

</script>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<Test:SampleDataBound runat="server" ID="d" EnableViewState="true" />

</div>

<asp:Button runat="server" ID="btn" Text="Refresh" />

</form>

</body>

</html>

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

public class SampleDataBound : CompositeDataBoundControl, INamingContainer

{

private Table table;

protected override int
CreateChildControls(System.Collections.IEnumerable dataSource, bool
dataBinding)

{

System.Collections.IEnumerator e = dataSource.GetEnumerator();

table = new Table();

this.Controls.Add(table);

TableRow row = null;

TableCell cell = null;

int count = 0;

while (e.MoveNext())

{

row = new TableRow();

cell = new TableCell();

if (dataBinding)

{

cell.Text = e.Current.ToString();

}

row.Cells.Add(cell);

table.Rows.Add(row);

count++;

}

return count;

}

}


Jul 5 '06 #2
God Bless you Teemu Keiski. I can't explain how I am happy now.

"Teemu Keiski" <jo****@aspalliance.comwrote in message
news:ec**************@TK2MSFTNGP02.phx.gbl...
Hi,

you have lines

row = new TableRow();
cell = new TableCell();
if (dataBinding)
{
cell.Text = e.Current.ToString();
}
row.Cells.Add(cell);
table.Rows.Add(row);

put them in different order

row = new TableRow();
table.Rows.Add(row);
cell = new TableCell();
row.Cells.Add(cell);

if (dataBinding)
{
cell.Text = e.Current.ToString();
}

e.g do databinding after cell is added to the Rows and so on.

Reason is that a ontrol like TableCell starts its lifecycle when it's
added to the Controls collection (even though here it's to Cells, but
that's basically just abstraction) and part of this lifecycle is to start
tracking state.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"Umut Tezduyar" <ut*******@gmail.comwrote in message
news:OG*************@TK2MSFTNGP04.phx.gbl...
>>I have a control derived from ComposeteDataBoundControl. Control doesn't
retreive it's state information. I am going to frick out! What should I
do
more?
I added two codes. One is for Default.aspx to Test the control
"SampleDataBound". When I click to the "Refresh" button here, the data
displayed in the SampleDataBound control become lost.

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

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server" type="text/C#">
protected override void OnLoad(EventArgs e)

{

base.OnLoad(e);

if (!Page.IsPostBack)

{

System.Collections.Generic.List<stringlist = new
System.Collections.Generic.List<string>();

list.Add("UMUT");

list.Add("Mehmet");

list.Add("Hasan");

this.d.DataSource = list;

this.d.DataBind();

}

}

</script>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<Test:SampleDataBound runat="server" ID="d" EnableViewState="true" />

</div>

<asp:Button runat="server" ID="btn" Text="Refresh" />

</form>

</body>

</html>

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

public class SampleDataBound : CompositeDataBoundControl,
INamingContainer

{

private Table table;

protected override int
CreateChildControls(System.Collections.IEnumerabl e dataSource, bool
dataBinding)

{

System.Collections.IEnumerator e = dataSource.GetEnumerator();

table = new Table();

this.Controls.Add(table);

TableRow row = null;

TableCell cell = null;

int count = 0;

while (e.MoveNext())

{

row = new TableRow();

cell = new TableCell();

if (dataBinding)

{

cell.Text = e.Current.ToString();

}

row.Cells.Add(cell);

table.Rows.Add(row);

count++;

}

return count;

}

}



Jul 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Lee | last post by:
Hello, This is a genral enquiry before I send out a more detailed request. I am unable to retreive image files from a mysql database using IE 5.2 on the mac OS X platform. I have built a...
3
by: Not4u | last post by:
I would like to know which products are my best sells by sellers, but i would like to retreive this info by product id, seller id and the total amount of sells for this product. My Sells table...
2
by: Robert V. Hanson | last post by:
If you have per user information that you want to store in session and the setting in web.config is set to cookieless=false so you are intending on using cookies, the user's browser is set to not...
2
by: Brad | last post by:
I have an intranet app that has just started sporadically getting the following error "The viewstate is invalid for this page and might be corrupted." By sproadic I mean 3-4 times during the past...
1
by: Sudhakara.T.P. | last post by:
Hi, I have an application in VB.NET windows application, wherein the administrator has the option to change the authentication mode ie., whether the application should work as a normal database...
4
by: robinsand | last post by:
Header File: car.h #if !defined CAR_H #define CAR_H enum TCarType { ctEconomy = 1, ctCompact, ctStandard, ctFullSize, ctMiniVan, ctSUV }; class Car { public: Car();
0
by: Umut Tezduyar | last post by:
I have a control derived from ComposeteDataBoundControl. Control doesn't retreive it's state information. I am going to frick out! What should I do more? I added two codes. One is for Default.aspx...
1
by: Griff | last post by:
Hi I want to create an n-tier custom server control. The idea is that the control will determine which "view" will be used. By this I mean User A may want the data displayed as a tree-view,...
28
by: ensemble | last post by:
I'm trying to utilized a more object-oriented approach to managing window events in javascript. Thus, I am creating a "controller" object to handle events and interact with the server. However, I...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.