Event on a textbox in a webcontrols.table is only fire every 2nd time.

T

Tommy

I have a webcontrols.table in my asp designer(VS.NET 2003). I build
rows and cells programaticly in a code_behind file. I place one
TextBox in every cell, with data from a sql-table. When the the data
in the TextBox is changed, I want to run a update proc on the
SQL-server, and then update the table, because it is some calculated
cells it in.
The data is a simple table with two columns: count_emploeee, and
sum_cost. The sum_cost is by default a calculated
cell(count_employee*price), but can be overwritten. The
select-stored-procedure in SQL-server is dealing this.
The problem is that the webcontrols.table's rows and cells has to be
built every visit to the page because it will not persist across
postbacks.

Some samplecode in C#:

form_load()
{
//it is not posible to know if the event is fireing. so I always have
to
//call the buildtable method.
// the form_load fires before the textbox_change
buildTable();
}

private void buildTable()
{
//refresh the dataset from the select proc on SQL-Server
Table1.Rows.Clear();
for( int rowCounter = 0;
rowCounter<dataSet.Tables[0].Rows.Count;rowCounter++)
{
TableRow aTableRow = new TableRow();
for( int colCounter = 0;
colCounter<dataSet.Tables[0].Columns.Count;colCounter++)
{
TableCell aCell = new TableCell();
TextBox textbox = new TextBox();
textbox.Text=tekst;
textbox.EnableViewState=true;
textbox.TextChanged += new EventHandler(textBox_change);
textbox.AutoPostBack=false;
aCell.Controls.Add(textbox);
aCell.EnableViewState=true;
aTableRow.Cells.Add(aCell);
}
TableBemanning.Rows.Add(aTableRow);
TableBemanning.EnableViewState=true;
}
}



protected void textBox_change(object sender, System.EventArgs e)
{
TextBox t = (TextBox)sender;
string updateValue = t.text;
//run the update proc on SQL-sever

//Because there are som columns in the table who is calculated on the
//updated cell, I have to update the dataset and
//refresh the table. Maybe it is here it goes wrong.
//the Buildtable() is called twice when the textbox is changing.

buildTable();
}


Every second time the textbox_change methode is fireing. TO fire the
update I use a simple <input type=submit> button.
The page consists of 3 different tables, who all needs to be updated
in the same way.

The time when it does not fire the event, the table is loaded with the
old data. So if I change the the value (old value)22 to (new value)33
the page is refreshed with the 22 in it.


I hope you can help me with some answers?

/Tommy Strandvold
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top