如何在ASP.NET中动态创建的控件中保留值 [英] How to preserve value in dynamically created controls in asp.net

查看:100
本文介绍了如何在ASP.NET中动态创建的控件中保留值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

海,

我正在使用c#在asp.net中创建一个网站,其中是动态添加单选按钮,也将按钮添加到具有事件的窗格中.但是当页面重新加载时并没有旧的控件.假设我创建了两个单选按钮是"和否".当我单击是"按钮时,页面正在重新加载并且正在获取新按钮.我想将旧值保存在数据库中,该怎么做?请帮帮我


谢谢
Sujith.

Hai,

I am doing one website in asp.net using c#, in that am dynamically adding radion button, buttons into pane with events also. But when page is reloading am not getting old control. Suppose i created two radio button Yes and No. When i click Yes button, page is reloading and am getting new button. I want to save old values in database, What to do for that? Please help me


Thanks
Sujith.

推荐答案

如果仅尝试在前端维护单选按钮值,则可以使用隐藏字段的功能.

就像页面的回发一样,单选按钮的值可能会丢失,但隐藏字段中的值将继续保留,然后您可以设置从数据库中获取的单选按钮的先前值.

如果您未对更改的单选按钮值执行数据库操作,则数据库值不会更改.

http://www.devmanuals.com/tutorials/ms/aspdotnet/hiddenfield.html [ ^ ]

http://dotnet.dzone.com/news/aspnet-client-side-state- manag-0 [^ ]

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hiddenfield.value.aspx [
If you are trying to maintain the radio button values in the front end only then you can use the functionality of hidden field .

As on the postback of your page the value of radio button may be lost but the values in hidden field will continue to persist and then you can set the previous value of radio button fetched from database.

And the database value doesn''t changes if you haven''t performed a database operation on the radio button value changed.

http://www.devmanuals.com/tutorials/ms/aspdotnet/hiddenfield.html[^]

http://dotnet.dzone.com/news/aspnet-client-side-state-manag-0[^]

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hiddenfield.value.aspx[^]

I hope this clears your problem. :)


请确保您在onLoad或之前创建了任何动态控件,否则,框架不会将任何值加载到其中.如果执行此操作,则会在回发时填充它们.您无需在后续响应中显示这些控件,购买它们确实需要及时存在,以便框架可以访问它们.
请参阅
http://msdn.microsoft.com/en-us/library/ms178472.aspx#general_page_lifecycle_stages [^ ]对于页面生命周期:了解这一点及其后果对ASP.NET开发很有用.
Make sure you create any dynamic controls onLoad or before, otherwise the famework doesn''t have anything to load the values into. If you do this, they will be populated on postback. You don''t need to display these controls in subsequent responses, buy they do need to be there in time for the framework to access them.
See http://msdn.microsoft.com/en-us/library/ms178472.aspx#general_page_lifecycle_stages[^] for the page lifecycle: understanding this and its consequences is useful to ASP.NET development.


这篇关于如何在ASP.NET中动态创建的控件中保留值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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