I have a web page which has a non determined number of sections (made up of a collection of textbox, dropdowns etc). A user clicks on "Add Section" button and this section should be added dynamically. There is no upper limit on how many sections a user can add. There is then a Save button at which time the I need to traverse through all the sections and persist the data.
我有一个网页,其中包含不确定数量的部分(由文本框,下拉列表等组成)。用户单击“添加部分”按钮,应该动态添加此部分。用户可以添加的部分没有上限。然后有一个Save按钮,此时我需要遍历所有部分并保留数据。
My first thought is to create the section as a user control that I dynamically add whenever a user clicks on the "Add section" on the server side.
我的第一个想法是将该部分创建为用户控件,只要用户单击服务器端的“添加部分”,我就会动态添加该控件。
I'd like to avoid doing adding user controls dynamically as I feel it's a little quirky. I am trying to understand if I can leverage jquery or client templates for the use case here.
我想避免动态添加用户控件,因为我觉得它有点古怪。我试图了解我是否可以在这里使用jquery或客户端模板作为用例。
Thoughts or suggestions?
想法或建议?
1 个解决方案
#1
1
I don't think there is any wrong in using user control solution. A similar (server side) technique would be to use a data-bound control such as Repeater or ListView - the item template would define the section. The advantage with server side solution is that it can be quickly built and can use ASP.NET infrastructure such as view-state (so that you don't have to worry about maintaining state on post-backs). Typical ASP.NET Forms developer would easily understand the logic. Flip side is that larger markup size, multiple large data transfers while adding sections (whether you use full or partial post-back will not matter much - view-state will be significant part of data being transfer).
我不认为使用用户控制解决方案有任何错误。类似的(服务器端)技术将使用数据绑定控件,如Repeater或ListView - 项模板将定义该部分。服务器端解决方案的优势在于它可以快速构建,并且可以使用ASP.NET基础结构,例如视图状态(这样您就不必担心在回发后维护状态)。典型的ASP.NET Forms开发人员很容易理解逻辑。翻转方面是更大的标记大小,多个大数据传输,同时添加部分(无论您使用完全或部分回发都无关紧要 - 视图状态将是传输数据的重要部分)。
I will personally prefer client templating approach because you avoid post-backs and associated data transfers. But there are two issues - a) relatively complex logic for displaying/updating sections - remember your code is fragmented at two places - js and server side code - typical developers would find it difficult to understand b) reliance of java-script (sometime, you must provide for a fallback mechanism if js is not supported)
我个人更喜欢客户端模板方法,因为您可以避免回发和相关的数据传输。但是有两个问题--a)显示/更新部分的相对复杂的逻辑 - 记住你的代码在两个地方碎片化 - js和服务器端代码 - 典型的开发人员会发现很难理解b)依赖java脚本(有时,如果不支持js,你必须提供回退机制)
#1
1
I don't think there is any wrong in using user control solution. A similar (server side) technique would be to use a data-bound control such as Repeater or ListView - the item template would define the section. The advantage with server side solution is that it can be quickly built and can use ASP.NET infrastructure such as view-state (so that you don't have to worry about maintaining state on post-backs). Typical ASP.NET Forms developer would easily understand the logic. Flip side is that larger markup size, multiple large data transfers while adding sections (whether you use full or partial post-back will not matter much - view-state will be significant part of data being transfer).
我不认为使用用户控制解决方案有任何错误。类似的(服务器端)技术将使用数据绑定控件,如Repeater或ListView - 项模板将定义该部分。服务器端解决方案的优势在于它可以快速构建,并且可以使用ASP.NET基础结构,例如视图状态(这样您就不必担心在回发后维护状态)。典型的ASP.NET Forms开发人员很容易理解逻辑。翻转方面是更大的标记大小,多个大数据传输,同时添加部分(无论您使用完全或部分回发都无关紧要 - 视图状态将是传输数据的重要部分)。
I will personally prefer client templating approach because you avoid post-backs and associated data transfers. But there are two issues - a) relatively complex logic for displaying/updating sections - remember your code is fragmented at two places - js and server side code - typical developers would find it difficult to understand b) reliance of java-script (sometime, you must provide for a fallback mechanism if js is not supported)
我个人更喜欢客户端模板方法,因为您可以避免回发和相关的数据传输。但是有两个问题--a)显示/更新部分的相对复杂的逻辑 - 记住你的代码在两个地方碎片化 - js和服务器端代码 - 典型的开发人员会发现很难理解b)依赖java脚本(有时,如果不支持js,你必须提供回退机制)