动态控件上的事件 [英] events on dynamic controls

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

问题描述

你好,

我正在页面上动态创建两个图像按钮,并在这些按钮的click事件上创建了更多图像按钮,但是当我尝试在新创建的按钮上触发click事件时,这些按钮变为不可见,并且没有事件为fire

Hello,

I am creating two image buttons dynamically on a page and on the click event of these buttons i am creating some more image buttons but when i am trying to fire click event on newly created buttons these buttons gone invisible and no event is fire

推荐答案

是的,因为您是在按钮的click事件上创建按钮的.这就是为什么新创建的按钮无法恢复该视图状态的原因. 最好在Page_InIt事件中创建按钮并使用户看不到它们.单击按钮后,您可以使那些创建的按钮可见.
否则,您需要还原控件的视图状态.在这种情况下,请参考链接:
在ASP.NET应用程序中为动态创建的控件保留状态 [ ^ ]
动态控制中的ViewState [
Yes, because you are creating the buttons on the click event of a button. That''s why the newly created buttons are unable to restore the viewstate for that.
Better you create your buttons in Page_InIt event and make them invisible to the user. On click of button you can make those created buttons visible.
Otherwise you need to restore the viewstate of the controls. In that case refer the link:
Retaining State for Dynamically Created Controls in ASP.NET applications[^]
ViewState in Dynamic Control[^]

--Amit


您好,

问题是对于动态创建的控件,视图状态无法保持.因此,您需要为动态创建控件创建viewstate.
请参阅以下链接.您将了解如何创建动态控件及其视图状态.

在ASP.NET应用程序中为动态创建的控件保留状态 [ ^ ]

希望对您有所帮助.

谢谢,
Viprat
Hello,

The problem is that for the dynamic created control view state is not maintain. So you need to create viewstate for dynamic create control.
See the following link. You will get the idea how to create the dynamic controls and its viewstate.

Retaining State for Dynamically Created Controls in ASP.NET applications[^]

I hope it might be help you.

Thanks,
Viprat




确保在页面生命周期的早期创建按钮,该按钮可能位于Page_Init或Page_Load中.因为,动态创建的按钮不保存视图状态.这就是为什么您每次必须在Page_Init或Page_Load上创建控件的原因.这也是因为事件处理将在页面Init阶段之后进行.因此,在Page_Init事件中创建图像"按钮,也仅在page_Init事件中分配onclick委托.然后尝试.

有关更多信息,请参考 [
Hi,

Make sure that you are creating the button early in the page life cycle, may be in Page_Init or Page_Load. Because, the dynamically created buttons does not hold view state. that is why you have to create the controls every time on Page_Init or Page_Load. also because the event handling will occur after the page Init stage. So, create the Image button in Page_Init event also assign onclick delegate in page_Init event only. then try.

for more refer this[^]

Hope it helps.


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

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