Ajax UpdatePanel + table не происходит асинхронного запроса
От: ParaD1Se  
Дата: 06.03.08 10:57
Оценка:
На странице расположено несколько UpdatePanel. Во всех кроме двух находятся статические Control'ы. А в двух лежат по 1 Table . Их содержимое генерируется динамически (добавляется несколько строк с TextBox'ами и DropDownBox'ом — у этих элементов AutoPostBack = true и создается событие по TextChanged)Проблема в том что если событие происходит у статических контролов то ScriptManager1.IsInAsyncPostBack = true и все работает великолепно. А вот у динамически сгенерированных ScriptManager1.IsInAsyncPostBack = false и перегружается не Updatepanel, а вся страница.



static public class TableHelper
{
       
    static public void CreateTable(System.Web.UI.WebControls.Table table, String[] col, int numCol)
    {
        int i;
        for (i = 0; i < numCol; i++)
        {
            AddRow(table, col, i);
        }
    }

    static public void AddRow(System.Web.UI.WebControls.Table table, String[] col)
    {
        table.Rows.Add(new TableRow());
        DropDownList ddlist = null;
        TextBox tbox = null;

        int numRow = table.Rows.Count - 1;
        table.Rows[numRow].Cells.Add(new TableCell());
        table.Rows[numRow].Cells[0].Controls.Add(new Label());
        table.Rows[numRow].Cells[0].Width = 90;
        ((Label)table.Rows[numRow].Cells[0].Controls[0]).Text = col[0];

        table.Rows[numRow].Cells.Add(new TableCell());

        ddlist = new DropDownList();
        ddlist.Width = 107;
        ddlist.AutoPostBack = true;

        table.Rows[numRow].Cells[1].Controls.Add(ddlist);


        int k = 1;
        for (int j = 2; j < col.Length * 2 - 5; j = j + 2)
        {
            table.Rows[numRow].Cells.Add(new TableCell());
            table.Rows[numRow].Cells[j].Controls.Add(new Label());
            table.Rows[numRow].Cells[j].Width = 80;
            table.Rows[numRow].Cells[j].HorizontalAlign = HorizontalAlign.Right;
            ((Label)table.Rows[numRow].Cells[j].Controls[0]).Text = col[k];

            table.Rows[numRow].Cells.Add(new TableCell());

            tbox = new TextBox();
            tbox.Width = 100;
            tbox.AutoPostBack = true;

            table.Rows[numRow].Cells[j + 1].Controls.Add(tbox);
            k++;
        }
        for (int j = col.Length * 2 - 4; j < col.Length * 2 - 1; j = j + 2)
        {
            table.Rows[numRow].Cells.Add(new TableCell());
            table.Rows[numRow].Cells[j].Controls.Add(new Label());
            table.Rows[numRow].Cells[j].Width = 80;
            table.Rows[numRow].Cells[j].HorizontalAlign = HorizontalAlign.Right;
            ((Label)table.Rows[numRow].Cells[j].Controls[0]).Text = col[k];

            table.Rows[numRow].Cells.Add(new TableCell());

            tbox = new TextBox();
            tbox.Width = 100;
            tbox.ID = table.ID + "_date_" + numRow.ToString() + "_" + j.ToString();
            table.Rows[numRow].Cells[j + 1].Controls.Add(tbox);


            CalendarExtender cext = new CalendarExtender();
            cext.TargetControlID = tbox.ID;
            cext.Format = "dd.MM.yyyy";

            table.Rows[numRow].Cells[j + 1].Controls.Add(cext);

            k++;
        }
    }
}



public partial class Customer : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

        StammdatenKunde customer = (StammdatenKunde)Session["Customer"];
        BenutzerbezogeneDaten bdaten = (BenutzerbezogeneDaten)Session["BenutzerbezogeneDaten"];
        if (!IsPostBack)
        {
              BindLestungenTable(customer, bdaten);
        }

        else
        {
            
            AllgemeineDaten daten = (AllgemeineDaten)Session["AllgemeineDaten"];
            
            Template page = (Template)Master;
            ScriptManager manager = page.GetScriptManager();
            if (manager.IsInAsyncPostBack)
            {
                string fromWhere = Request["ctl00$ScriptManager1"];

                if (fromWhere.Contains("Button1"))
                {

                }
                else
                {
                    BindLestungenTable(customer, bdaten);
                }
            }
            else
            {

                BindLestungenTable(customer, bdaten);
            }
           

        }

       
    }


  
    protected void BindLestungenTable(StammdatenKunde customer, BenutzerbezogeneDaten daten)
    {
        for (int i = 0; i < customer.Leistung.Length; i++)
        {
            BindLestungenRow(customer.Leistung[i], i, daten);
        }

    }

    protected void BindLestungenRow(Leistung item, int i, BenutzerbezogeneDaten daten)
    {

        String[] head1 = {"Leistungsart:","Menge:","Preis:","Beginn:","Ende:"};
        TableHelper.AddRow(Table1, head1);
            TableRow row = Table1.Rows[i];

            FillingHelper.FillingKundenLeistungsart(daten, (DropDownList)row.Cells[1].Controls[0]);
            FillingHelper.SetupSomethingById(item.Leistungsart, (DropDownList)row.Cells[1].Controls[0]);

            if (item.MengeSpecified)
            {
                ((TextBox)row.Cells[3].Controls[0]).Text = item.Menge.ToString();
            }

            ((TextBox)row.Cells[5].Controls[0]).Text = item.Preis.ToString();

            if (item.BeginnSpecified)
            {
                ((TextBox)row.Cells[7].Controls[0]).Text = item.Beginn.ToShortDateString();
            }

            if (item.EndeSpecified)
            {
                ((TextBox)row.Cells[9].Controls[0]).Text = item.Ende.ToShortDateString();
            }


            ((DropDownList)row.Cells[1].Controls[0]).SelectedIndexChanged += new System.EventHandler(this.SaveLestungenTable);
            ((TextBox)row.Cells[3].Controls[0]).TextChanged += new System.EventHandler(this.SaveLestungenTable);
            ((TextBox)row.Cells[5].Controls[0]).TextChanged += new System.EventHandler(this.SaveLestungenTable);
            ((TextBox)row.Cells[7].Controls[0]).TextChanged += new System.EventHandler(this.SaveLestungenTable);
            ((TextBox)row.Cells[9].Controls[0]).TextChanged += new System.EventHandler(this.SaveLestungenTable);

    }


}
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.