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

Discussion in 'ASP .Net Web Controls' started by Tommy, Dec 9, 2003.

  1. Tommy

    Tommy Guest

    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

    Some samplecode in C#:

    //it is not posible to know if the event is fireing. so I always have
    //call the buildtable method.
    // the form_load fires before the textbox_change

    private void buildTable()
    //refresh the dataset from the select proc on SQL-Server
    for( int rowCounter = 0;
    TableRow aTableRow = new TableRow();
    for( int colCounter = 0;
    TableCell aCell = new TableCell();
    TextBox textbox = new TextBox();
    textbox.TextChanged += new EventHandler(textBox_change);

    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.


    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
    Tommy, Dec 9, 2003
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.