客户端内联表单编辑
我看到一些网站使用动态表单(我不知道如何调用它们!)来编辑一组数据。例如:有一组数据,如姓名、城市、国家等。当用户单击“编辑”按钮时,不是进行回发,而是动态打开一个由 2 个文本框 + 2 个组合框组成的表单进行编辑,然后当您单击“保存”按钮时,编辑表单消失,所有数据都会更新。
现在,我知道这里发生的事情是使用 Ajax 进行服务器调用和一些 javascript 进行 dom 操作。我什至找到了一些用于文本框编辑的 jquery 插件。但是,我找不到任何用于表单字段的完整实现的东西。因此,我通过 jquery ajax 调用和手动 dom 操作在 asp.net 上实现了它。这是我的过程:
1)当单击“编辑”按钮时:对服务器进行 ajax 调用以检索必要的 formit.aspx 2) 它返回已分配值的可编辑表单字段。 3)当单击“保存”按钮时:对服务器进行ajax调用以检索formupdateprocess.aspx页面。它基本上执行数据库更新,然后返回必要的 DOM 片段(...)来插入当前页面..
很好,它可以工作,但我的问题是性能.. 结果似乎比我在其他网站上看到的示例慢。:((
在那里有什么我不知道的更好的方法吗?
I see some web sites use dynamic forms(I am not sure about how to call them!) to edit a group of data. For example: there is a group of data such as name, last name, city, country.etc. when user clicks on EDIT button, instead of doing postback, a form, consisisting of 2 textboxes + 2 comboboxes, dynamically opens to edit,And then when you click on Save button, edit form disappears, and all data updates..
Now, I know what happens over here is using Ajax for server calls and some javascript for dom manipulation.. I even found some jquery plugins for textbox editing.. However, I could not found anything for full implementation of form fields. Therefore I have implemented it on asp.net by jquery ajax calls and dom manipulation manually. here is my process:
1) when Edit button clicked: Make a ajax call to server to retrieve necessary formedit.aspx
2) it returns editable form fields with values assigned.
3) when Save button clicked: make ajax call to server to retrieve formupdateprocess.aspx page. it basically do the database updates and then return necessary DOM snipplet (...) to insert current page..
well ıt works but MY PROBLEM, is performance.. Result seems slower than samples I see in other sites.:((
IS there anything that I dont know? a better way to implement this??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我会将编辑表单保留在客户端上,但用例如“style =“display:none;”隐藏,然后在用户单击编辑按钮时显示它。在这种情况下从服务器加载表单的性能成本非常高 这
这是一个非常基本的示例,没有考虑定位编辑表单等。
确实意味着您的主页必须在第一次加载时携带编辑字段值,但通常这是一个很小的代价,因为用户。接受当时的等待,而不是当他们单击按钮时。
I would keep the edit form on the client, but hidden with e.g. "style="display:none;", and then show it when the user clicks the edit button. Loading a form from the server in this event is very costly performance wise.
This is a very basic example and doesn't consider positioning the edit form etc.
This does mean your main page will have to carry the edit field values from first load, but very often that is a small price to pay, because the user accepts a wait at that time, not when they click a button.
我过去曾将 jQGrid 与 ASP.NET 一起使用(MVC 不支持 GridViews)。
http://www.trirand.com/blog/
和演示
http://trirand.com/jqgrid/jqgrid.html
(查看行编辑)。
I've used jQGrid in the past with ASP.NET (MVC doesn't support GridViews).
http://www.trirand.com/blog/
and demos at
http://trirand.com/jqgrid/jqgrid.html
(Check out the Row Editing ones).
只是一个想法,但是您是否看过 Jeditable 插件,它允许您编辑内联内容?
这是一个 教程,以及带有 一些改进。
Just an idea, but have you looked at Jeditable plugin which allows you to edit inline content?
And here is a tutorial, and the tutorial code with some improvements.
如果您像我一样讨厌时不时使用插件,那么这是如何完成的。
HTML:
然后是 CSS 来让事情变得更酷:
然后是 JavaScript:
所以当有人将鼠标悬停在 li 项目上时,它会变成蓝色,只是某种颜色,让用户知道他们可以编辑。当他们使用
dblclick
事件双击时,会显示一个表单,其中包含项的值,只需检查代码即可。当他们在表单中编辑并保存时,表单将被删除,并放置一个包含新
htmlvalue
的列表。然后,您可以使用$ajax
方法将变量发送到服务器端进行处理。Here is how it is done if you are like me who loathes using plugins now and again.
The HTML:
Then the CSS to cool things up:
Then the JavaScript:
So when someone hovers over the li items it turns blue just some colour to let the user know they can edit. When they double-click using the
dblclick
event, a form shows up with the value of the<li>
item, just check the code. When they edit in the form and save, the form is removed and a list with the newhtmlvalue
is placed. You can then use an$ajax
method to send the variables to the server side for processing.