简体   繁体   English

如何在ASP.NET中保持动态控件的状态?

[英]How to keep the state of dynamic controls in ASP.NET?

I am creating some dynamic textboxes through javascript, when postback is happening i am loosing the controls. 我通过JavaScript创建一些动态文本框,发生回发时,我失去了控件。 I can't use Ajax instead of postback and i can't create dynamic controls from code behind. 我不能使用Ajax代替回发,也不能从后面的代码创建动态控件。

Can anyone please give any suggestion about it? 有人可以提出任何建议吗?

If you create controls on client in javascript they will not be created for you on server side because server side doesn't know about them. 如果您使用javascript在客户端上创建控件,则不会在服务器端为您创建控件,因为服务器端不知道这些控件。 If you want data posted from these controls you can access them by Request.Form collection. 如果要从这些控件中发布数据,则可以通过Request.Form集合访问它们。

Can you not just create the textboxes server side, and show/hide via javascript/CSS? 您不仅可以创建文本框服务器端,还可以通过javascript / CSS显示/隐藏吗? This prevents javascript doing any creating of controls and concentrates on the correct displaying of the user interface. 这样可以防止javascript进行任何控件创建,并专注于正确显示用户界面。 The server knows all the controls on the page, and can deal with the business logic appropriately. 服务器知道页面上的所有控件,并且可以适当地处理业务逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM