Asp.net 部分回发后文本框数据丢失

Asp.net 部分回发后文本框数据丢失,asp.net,ajax,Asp.net,Ajax,我使用了更新面板,在更新面板中,我保留了ASP表格控件,在该控件中,我动态创建行,而行又包含1个下拉列表和3个文本框。我的问题是,在找到部分回发文本框和下拉列表后,文本框的文本属性显示为空,下拉列表的选定值设置为该框中的第一条记录。我还将整个表存储在会话中,并在中检索它!页面加载事件时的isPostBack条件。请指导我如何解决这个问题 我的.aspx页面的一部分如下所示 <td colspan="2"> <asp:ScriptManager ID

我使用了更新面板,在更新面板中,我保留了ASP表格控件,在该控件中,我动态创建行,而行又包含1个下拉列表和3个文本框。我的问题是,在找到部分回发文本框和下拉列表后,文本框的文本属性显示为空,下拉列表的选定值设置为该框中的第一条记录。我还将整个表存储在会话中,并在中检索它!页面加载事件时的isPostBack条件。请指导我如何解决这个问题

我的.aspx页面的一部分如下所示

<td colspan="2">
               <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server" EnableViewState="true">
                <ContentTemplate>  
                  <table class="style1">
                   <tr>
                     <td>
                        <table class="style1" border="1">
                        <tr>
                           <td width="120">
                                <asp:Label ID="QualificationLbl" runat="server" Text="Qualification"></asp:Label>                                           </td>
                                            <td  width="100">
                                                <asp:Label ID="PercentageLbl" runat="server" Text="Percentage"></asp:Label>
                                            </td>
                                            <td width="100">
                                                <asp:Label ID="YearLbl" runat="server" Text="Passing Year"></asp:Label>
                                            </td>
                                            <td width="*">
                                                <asp:Label ID="InstituteLbl" runat="server" Text="Institute Name" Width="120px" 
                                                    onprerender="InstituteLbl_PreRender"></asp:Label>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="4" align="left">
                                                <asp:PlaceHolder ID="PlaceHolder" runat="server"></asp:PlaceHolder>
                                                <asp:Table ID="Table1" runat="server">
                                                </asp:Table>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Button ID="addRowBtn" runat="server" onclick="addRowBtn_Click" 
                                        Text="Add New Row" />
                                </td>
                            </tr>
                        </table>
                  </ContentTemplate>
                    <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="addRowBtn" EventName="Click" />
                    </Triggers>

            </asp:UpdatePanel>
            <br />
    </td>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using AppResumeMaster;
using AppQualificationDetail;


public partial class Applicant_ApplicationForm : System.Web.UI.Page
{
    int Rows = 1;
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
        generateTable(Rows);
    }
    else
    {
        Table ReturnedTable = new Table();
        ReturnedTable = (Table)Session["Table"];
        int rowCount = ReturnedTable.Rows.Count;
        int colCount = 4;

        DropDownList objList = new DropDownList();
        TextBox txtBox = new TextBox();
        if (ReturnedTable != null)
        {
            for (int Rcount = 0; Rcount < rowCount; Rcount++)
            {
                for (int Ccount = 0; Ccount < colCount; Ccount++)
                {
                    if (Ccount == 0)
                    {
                        objList = (DropDownList)ReturnedTable.Rows[Rcount].Cells[Ccount].FindControl("DropDownList(" + Rcount + "," + Ccount + ")");
                        objList.SelectedValue = ((DropDownList)ReturnedTable.Rows[Rcount].Cells[Ccount].FindControl("DropDownList(" + Rcount + "," + Ccount + ")")).SelectedValue;
                    }
                    else
                    {
                        txtBox = (TextBox)ReturnedTable.Rows[Rcount].Cells[Ccount].FindControl("TextBox(" + Rcount + "," + Ccount + ")");
                        txtBox.Text = ((TextBox)ReturnedTable.Rows[Rcount].Cells[Ccount].FindControl("TextBox(" + Rcount + "," + Ccount + ")")).Text;
                        //txtBox.Text = Request.Params["TextBox(" + Rcount + "," + Ccount + ")"];
                    }
                }
            }

        }
    }

}
protected void saveBtn_Click(object sender, EventArgs e)
{
}
protected void addRowBtn_Click(object sender, EventArgs e)
{

    if (ViewState["rowCount"] != null)
    {
        Rows = Convert.ToInt32(ViewState["rowCount"].ToString());
        generateTable(Rows);
    }

}
public void generateTable(int rowCount)
{
    try
    {
        int colCount = 4;
        DropDownList objDropDownList;
        for (int Row = 0; Row < rowCount; Row++)
        {
            TableRow objTablerow = new TableRow();

            for (int cols = 0; cols < colCount; cols++)
            {
                TableCell objTableCell = new TableCell();
                if (cols == 0)
                {
                    objDropDownList = new DropDownList();
                    objDropDownList.Width = 120;
                    objTableCell.Controls.Add(objDropDownList);

                    DataOperation objDataoperation = new DataOperation();
                    DataSet ds = new DataSet();
                    ds = objDataoperation.DropDownList("select * from tblQualificationMaster");

                    objDropDownList.DataValueField = ds.Tables[0].Columns[0].ToString();
                    objDropDownList.DataTextField = ds.Tables[0].Columns[1].ToString();
                    objDropDownList.DataSource = ds.Tables[0];
                    objDropDownList.DataBind();

                    objDropDownList.ID = "DropDownList(" + Row + "," + cols + ")";
                    objTableCell.Controls.Add(objDropDownList);
                    objTablerow.Controls.Add(objTableCell);
                }
                else
                {
                    TextBox objTextBox = new TextBox();
                    objTextBox.ID = "TextBox(" + Row + "," + cols + ")";
                    objTableCell.Controls.Add(objTextBox);
                    objTablerow.Controls.Add(objTableCell);
                }
            }

            Table1.Rows.Add(objTablerow);

        }
        rowCount++;
        ViewState["rowCount"] = rowCount;
    }
    catch (Exception ex)
    {
        throw ex;
    }
}
protected void InstituteLbl_PreRender(object sender, EventArgs e)
{
    Session.Add("Table", Table1);
}
}
我的.aspx.cs页面如下所示

<td colspan="2">
               <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server" EnableViewState="true">
                <ContentTemplate>  
                  <table class="style1">
                   <tr>
                     <td>
                        <table class="style1" border="1">
                        <tr>
                           <td width="120">
                                <asp:Label ID="QualificationLbl" runat="server" Text="Qualification"></asp:Label>                                           </td>
                                            <td  width="100">
                                                <asp:Label ID="PercentageLbl" runat="server" Text="Percentage"></asp:Label>
                                            </td>
                                            <td width="100">
                                                <asp:Label ID="YearLbl" runat="server" Text="Passing Year"></asp:Label>
                                            </td>
                                            <td width="*">
                                                <asp:Label ID="InstituteLbl" runat="server" Text="Institute Name" Width="120px" 
                                                    onprerender="InstituteLbl_PreRender"></asp:Label>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="4" align="left">
                                                <asp:PlaceHolder ID="PlaceHolder" runat="server"></asp:PlaceHolder>
                                                <asp:Table ID="Table1" runat="server">
                                                </asp:Table>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Button ID="addRowBtn" runat="server" onclick="addRowBtn_Click" 
                                        Text="Add New Row" />
                                </td>
                            </tr>
                        </table>
                  </ContentTemplate>
                    <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="addRowBtn" EventName="Click" />
                    </Triggers>

            </asp:UpdatePanel>
            <br />
    </td>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using AppResumeMaster;
using AppQualificationDetail;


public partial class Applicant_ApplicationForm : System.Web.UI.Page
{
    int Rows = 1;
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
        generateTable(Rows);
    }
    else
    {
        Table ReturnedTable = new Table();
        ReturnedTable = (Table)Session["Table"];
        int rowCount = ReturnedTable.Rows.Count;
        int colCount = 4;

        DropDownList objList = new DropDownList();
        TextBox txtBox = new TextBox();
        if (ReturnedTable != null)
        {
            for (int Rcount = 0; Rcount < rowCount; Rcount++)
            {
                for (int Ccount = 0; Ccount < colCount; Ccount++)
                {
                    if (Ccount == 0)
                    {
                        objList = (DropDownList)ReturnedTable.Rows[Rcount].Cells[Ccount].FindControl("DropDownList(" + Rcount + "," + Ccount + ")");
                        objList.SelectedValue = ((DropDownList)ReturnedTable.Rows[Rcount].Cells[Ccount].FindControl("DropDownList(" + Rcount + "," + Ccount + ")")).SelectedValue;
                    }
                    else
                    {
                        txtBox = (TextBox)ReturnedTable.Rows[Rcount].Cells[Ccount].FindControl("TextBox(" + Rcount + "," + Ccount + ")");
                        txtBox.Text = ((TextBox)ReturnedTable.Rows[Rcount].Cells[Ccount].FindControl("TextBox(" + Rcount + "," + Ccount + ")")).Text;
                        //txtBox.Text = Request.Params["TextBox(" + Rcount + "," + Ccount + ")"];
                    }
                }
            }

        }
    }

}
protected void saveBtn_Click(object sender, EventArgs e)
{
}
protected void addRowBtn_Click(object sender, EventArgs e)
{

    if (ViewState["rowCount"] != null)
    {
        Rows = Convert.ToInt32(ViewState["rowCount"].ToString());
        generateTable(Rows);
    }

}
public void generateTable(int rowCount)
{
    try
    {
        int colCount = 4;
        DropDownList objDropDownList;
        for (int Row = 0; Row < rowCount; Row++)
        {
            TableRow objTablerow = new TableRow();

            for (int cols = 0; cols < colCount; cols++)
            {
                TableCell objTableCell = new TableCell();
                if (cols == 0)
                {
                    objDropDownList = new DropDownList();
                    objDropDownList.Width = 120;
                    objTableCell.Controls.Add(objDropDownList);

                    DataOperation objDataoperation = new DataOperation();
                    DataSet ds = new DataSet();
                    ds = objDataoperation.DropDownList("select * from tblQualificationMaster");

                    objDropDownList.DataValueField = ds.Tables[0].Columns[0].ToString();
                    objDropDownList.DataTextField = ds.Tables[0].Columns[1].ToString();
                    objDropDownList.DataSource = ds.Tables[0];
                    objDropDownList.DataBind();

                    objDropDownList.ID = "DropDownList(" + Row + "," + cols + ")";
                    objTableCell.Controls.Add(objDropDownList);
                    objTablerow.Controls.Add(objTableCell);
                }
                else
                {
                    TextBox objTextBox = new TextBox();
                    objTextBox.ID = "TextBox(" + Row + "," + cols + ")";
                    objTableCell.Controls.Add(objTextBox);
                    objTablerow.Controls.Add(objTableCell);
                }
            }

            Table1.Rows.Add(objTablerow);

        }
        rowCount++;
        ViewState["rowCount"] = rowCount;
    }
    catch (Exception ex)
    {
        throw ex;
    }
}
protected void InstituteLbl_PreRender(object sender, EventArgs e)
{
    Session.Add("Table", Table1);
}
}

我想通过保留以前的行,在每个addRowTbn click事件上添加一行。

从我的第一次查看中,您正在尝试从会话中存储的表中提取下拉列表的选定值和文本框的文本值,但在用户有机会更改值之前,您已将该表存储在会话中。

感谢Zach的回复,但我不明白您想说什么。请指导我如何解决这个问题。。。