提交后从动态创建的TextBox中获取值 [英] Get values from dynamically created TextBoxes after submit

查看:79
本文介绍了提交后从动态创建的TextBox中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...
我想做的是从数据库中获取数据,用户可以编辑添加多个新数据行并将其提交回服务器.
因此,这是一个简化的示例...我们有一个简单的数据库,其中包含日期,旅行目的地,酒店名称和主键的三联号.这在名为BusinessTrip的表中.
我们想要做的是让用户能够创建新行程或查看和编辑现有行程.因此,如果他们查看现有行程,则会在页面下方显示第1天-日期,旅行目的地,酒店名称,然后显示第2天-日期,旅行目的地,酒店名称等.
为此,我们在aspx页上创建了一个表格,并通过捕获数据源选择事件并填充每个文本框,在后面的代码中手动添加了包含单元格的行,这些单元格包含文本框控件.我们还提供了一个javascript函数,可将新行动态添加到表中,使它们可能需要花费额外的时间.但是,如果用户编辑任何文本框数据或添加新行,然后单击提交,则任何动态创建的数据都将丢失,这部分效果很好.我尝试捕获数据源更新事件,并希望手动填充数据源,但是到了这一步,我已经丢失了动态创建的文本框中的数据.有什么办法可以从动态创建的控件中保留此信息?有没有更好的办法解决这个问题.我们已经看到了FormViews的编辑功能,但是似乎非常烦人的是,用户必须先单击编辑,然后在每行更改后刷新页面,如果添加了一行,则页面也会更新.
任何帮助,将不胜感激.
谢谢

Hi...
What I am trying to do is take in data from a database that a user can edit add multiple new rows of data and submit it back to the server.
So a simplified example is this... We have a simple database with a date, Travel Destination, Hotel Name and a tripid for the primary key. This is in a table called BusinessTrip.
What we would like to do is have a user able to either create a new trip or view and edit an existing trip. So if they view an exisiting trip it would bring up day 1 - Date, Travel Destination, Hotel Name then Day 2 - Date, Travel Destination, Hotel Name etc etc. down the page.
To accomplish this we have created a table on the aspx page and manually added rows consisting of cells containing textbox controls in the code behind by capturing the datasource selecting event and populating each text box. We also have a javascript function to dynamically add new rows to the table for extra days they may be travelling. This part works fine however if the user edits any of the text box data or adds new rows and then hits the submit any of the dynamically created data is lost. I have tried catching the datasources updating event and wanted to manually populate the datasource however by this stage I have already lost the data in the dynamically created text boxes. Is there any way of retaining this information from a dynamically created control? IS there any better way of perhaps going about this. We have seen the FormViews edit functions however it seems very annoying that the user has to firstly hit edit and the page refreshes after each row they change and if they add a row the page is updated.
Any help would be appreciated.
Thanks

推荐答案

丹尼,

首先,您应该没有asp.net页面生命周期...
我在一个项目中遇到过同样的问题,我们正在创建具有一些子控件的动态用户控件...这里的逻辑很简单,您必须在页面加载之前捕获动态数据,即在page_preinit中并将其存储在同一会话中. br/>
试试这个


问候
Vinay
Hi Danny,

First u should no the asp.net page life cycle...
I have faced same issue in one of project where we are creating dynamic user controls having some child controls...here the logic is simple you have to capture the dynamic data befor the page load i.e in page_preinit and store it in same session.

Try this one


Regards
Vinay


这篇关于提交后从动态创建的TextBox中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆