ascx控件中动态表的问题
我在 ascx 用户控件中有下表:
<tr runat="server" id="rowChangeSerNo">
<td colspan="2">
<table id="tblChangeSerNo" runat="server">
</table>
</td>
</tr>
<tr id="row" runat="server">
<td>
<asp:Button ID="btChangeSerNo" runat="server" Text="Update" OnClick="btChangeSerNo_onClick" />
</td>
</tr>
我使用预先填充了数据库中当前值的文本框动态创建 tblChangeSerNo
。该控件的想法是允许用户用新值更新数据库的值。问题是,当调用 btChangeSerNo_onClick
方法时:
- 该表未呈现,因为我在预呈现时执行此操作
- 即使我在 Page_Load 上呈现该表,我也无法访问用户的更新值,因为他们迷路了。
我该如何解决这个问题?
I have the following table in an ascx user controll:
<tr runat="server" id="rowChangeSerNo">
<td colspan="2">
<table id="tblChangeSerNo" runat="server">
</table>
</td>
</tr>
<tr id="row" runat="server">
<td>
<asp:Button ID="btChangeSerNo" runat="server" Text="Update" OnClick="btChangeSerNo_onClick" />
</td>
</tr>
I create the tblChangeSerNo
dynamically with text boxes prefilled with the current values in the db. The idea of the control is to allow the user to update the values of the DB with new values. The problem is that when the btChangeSerNo_onClick
method is called:
- The table is not rendered, since I do it on pre-render
- Even if I rendered the table on Page_Load I could not access updated values of the user because they are lost.
How can I solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最佳实践方法是使用网格控件。
如果您希望坚持使用自己的代码,请按照下列步骤操作:
public Listm_tableTextboxes = new List();
并在创建时添加到该列表。Page_Load
中创建动态控件,但仅在不是 PostBack 时才执行:if (!Page.IsPostBack) { ... }
过去做过类似的事情,所以这个概念应该有效。
The best practice way will be to use Grid control instead.
If you prefer to stick with your own code, follow those steps:
public List<TextBox> m_tableTextboxes = new List<TextBox>();
and when creating add to that list.Page_Load
but execute it only when not is PostBack:if (!Page.IsPostBack) { ... }
Done something similar in the past, so the concept should work.