动态控制和视图状态 [英] Dynamic Control and View State

查看:95
本文介绍了动态控制和视图状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

需要有关任务的帮助.一个带有静态文本框和一个名为生成"的按钮的.aspx页面.我们必须在文本框中输入数字(例如4),然后在生成"按钮上,单击四(4)动态下拉列表,并创建一个名为"ADD"的按钮.第一个动态下拉列表包含数字1到10,第二个动态下拉列表包含数字10到20,依此类推...单击动态生成的按钮"ADD"按钮后,四个动态创建的下拉列表中的所选值将被添加并显示在另一个动态创建的列表中标签和下拉列表应分别包含选定的值,而不包含任何javascript或jquery.基本上与页面生命周期和视图状态有关.有人可以帮忙吗?

谢谢所有朋友.在此问题上寻求您的帮助.

Hi Friends,

need a help regarding an assignment. An .aspx page with a static textbox and a button named "Generate". we have to enter a number in the textbox (say 4) then on the Generate button click four(4) dynamic dropdownlist are created and a button named "ADD" is also created. The first dynamic dropdown contains number 1 to 10 and second dynamic dropdown contains 10 to 20 and so on... On clicking the dynamically generated button "ADD" button the selected values on the four dynamically created dropdownlist will added and shown in another dynamically created label and the dropdown should contain the selected values respectively without any javascript or jquery. basically its somewhat related to page lifecycle and viewstate. Can anybody please help?

Thanking You all friends. Looking for your kind help on the issue.

推荐答案

您绝对可以在不使用javascript或jquery的情况下实现此目的.在这里,主要的问题是您松开了动态创建的UI或单击"ADD"按钮后的值.诀窍是在回发时重新创建UI.

1.将所有动态UI生成都保留在一个方法中,例如CreateDynamicUI()

2.在CreateDynamicUI()中,确保跟踪所有UI元素并分配唯一的ID.

3.为了在每次回发中重新创建UI,请在aspx
的Page_Load()中调用CreateDynamicUI().
4.在"ADD"按钮的单击事件中,执行FindControl来获取动态创建的元素的句柄.

我建议将所有动态内容依次添加到一个单独的父控件(例如面板或表格)中,以使解析变得容易.
You can definitely achieve this without using javascript or jquery. Here, the major problem is that you loose the dynamically created UI or the values on the post back of your "ADD" button click. The trick is to recreate your UI on postbacks.

1. Keep all your dynamic UI generation in one single method, say CreateDynamicUI()

2. In your CreateDynamicUI() ensure that you keep track of all the UI elements and assign unique IDs.

3. In-order to recreate UI on every postback, call CreateDynamicUI() in the Page_Load() of your aspx

4. In the "ADD" button click event, do a FindControl to get handles to the dynamically created elements.

I recommend to add all the dynamic content to one single parent control such as a panel or a table in-order to make the parsing easy.


我今天回答了您:http://www.codeproject.com/Messages/4371298/Re-Dynamic-Control-Help.aspx [^ ]

为什么要重新发布?你试过了吗?请尝试并发布特定问题.
步骤:
1.定义GENERATE Button单击处理程序X
2.在X中,获取文本框中提供的数字(例如y)
3.定义一个计数器(例如z).将其设置为一个.
4.将for循环从零编码为y-1(循环运行y次)
5.使用new在循环内创建一个下拉列表.

  • 提供ID
  • 定义数据源-列表
  • 从z开始以固定的10个数字填充列表.对于第一个循环,z从1到10,接下来的11-20 ...
  • 将数据源绑定到dropdonw
  • 将下拉列表添加到UI中定义的面板/占位符
I replied you today: http://www.codeproject.com/Messages/4371298/Re-Dynamic-Control-Help.aspx[^]

Why a repost? Did you try it? Please try and post specific issue.
Steps:
1. Define a GENERATE Button click handler X
2. In X, get the number provided in Textbox (say y)
3. Define a counter(say z). Set it to one.
4. Code a for loop from zero to y-1 (loop runs y times)
5. Create a dropdownlist inside the loop using new.

  • Provide ID
  • Define a datasource - a list
  • Populate list with fixed 10 numbers starting from z. for first loop z goes from 1 to 10, next 11-20...
  • Bind the datasource to dropdonw
  • Add the dropdown to the defined panel/placeholder in UI


Sandeep已获得创建和管理动态Asp.Net控件的步骤.如果在创建控件时需要更多帮助或指导,请参考类似文章的链接:
在ASP.NET中动态创建的控件 [使用动态创建的控件 [在ASP.NET中动态创建的控件 [动态创建ASP.NET控件 [
Sandeep is already given the steps to create and manage Dynamic Asp.Net controls. If you need little more help or guideline while creating the controls then refer the links for similar articles:
Dynamically Created Controls in ASP.NET[^]
Working with Dynamically Created Controls[^]
Dynamically Created Controls in ASP.NET[^]
Creating ASP.NET Controls Dynamically[^]


--Amit


这篇关于动态控制和视图状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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