文本属性覆盖

时间:2015-04-30 18:49:00

标签: c# asp.net

我的ListView的EditItemTemplate中有一个文本框和一个链接按钮:

<asp:TextBox ID="txt_notes" runat="server" Placeholder='<%# Eval("notes") %>'></asp:TextBox>
<asp:LinkButton ID="btn_update" class="btn btn-sm btn-success" OnClick="btn_update_Click" CommandArgument='<%# Eval("carID") %>' runat="server" >Update</asp:LinkButton>

我有这段代码:

protected void btn_update_Click(object sender, EventArgs e)
{
    var btn_update = (LinkButton)sender;
    int ID = System.Convert.ToInt32(btn_update.CommandArgument);
    TextBox txt_notes = (TextBox)listview.EditItem.FindControl("txt_notes");
    string notes = txt_notes.Text;
}

现在当我在string notes = txt_notes.Text设置一个断点时,它说txt_notes.Text中没有任何内容,即使我在文本框中输入了一些东西,所以它似乎被ItemDataBound或PageLoad覆盖了

有谁知道我应该如何克服这个问题?

1 个答案:

答案 0 :(得分:0)

看起来您在页面加载时绑定了listview,但没有检查它是否在回发上。试试下面的

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        listview.DataSource = your_data_source;
        listview.DataBind();
     }
}