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

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason Shohet
    Replies:
    1
    Views:
    327
    Jason Shohet
    Jun 17, 2004
  2. sonic
    Replies:
    0
    Views:
    341
    sonic
    Feb 3, 2005
  3. =?Utf-8?B?SXJ3YW5zeWFo?=
    Replies:
    4
    Views:
    2,441
    =?Utf-8?B?SXJ3YW5zeWFo?=
    Oct 30, 2007
  4. Replies:
    0
    Views:
    125
  5. Monica

    fire a method or event every hour automatically?

    Monica, Jun 27, 2008, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    177
    Tanzim Saqib
    Jul 1, 2008
Loading...

Share This Page