在DataGrid中添加动态控件时,事件处理程序丢失 [英] Event Handler Lost when Dynamic Controls are added in a DataGrid

查看:67
本文介绍了在DataGrid中添加动态控件时,事件处理程序丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我一直在尝试在我的ASP.NET页面上添加一个控件到

数据网格的标题单元格。这些控件在HTML中定义为

作为ASP.NET Web控件。

它们被添加到数据网格的标题中

"&的ItemDataBound QUOT;网格的方法。但是,有一次,

它们被添加到网格中,我似乎失去了相同控件的事件

处理程序。有没有人曾经有过b $ b尝试过这个问题,知道为什么会这样吗?


预付谢谢

Ashish Shridharan

Hi All
I have been trying to add a control to the header cell of
a datagrid on my ASP.NET page. These controls are defined
in the HTML as ASP.NET web controls.
They are being added into the header of the datagrid in
the "ItemDataBound" method of the grid. However, once,
they are added in the grid, i seem to lose the event
handler for the same control. Is there anyone who has
tried this before and knows why this is hapenning ??

Thanks in Advance
Ashish Shridharan

推荐答案

是的,我做过类似的事情。这是一种痛苦。


你失败了你的事件处理程序,因为控件是动态的
,如果你做回发,它不知道

控件是否存在,即使它可能在viewstate中。


你必须在OnInit中重新创建控件。
Yes, I have done something like that. It is a PAIN.

You''re "losing" your event handler because the control is
dynamic and if you do a postback it doesn''t know that the
control exists, even though it may be in the viewstate.

you will have to recreate the control in the OnInit.
-----原始消息-----
大家好
我一直在尝试将控件添加到我的ASP.NET页面上的数据网格的标题单元格中。这些控件在HTML中定义为ASP.NET Web控件。
它们被添加到数据网格的标题中的ItemDataBound中。网格的方法。但是,有一次,它们被添加到网格中,我似乎失去了同一控件的事件处理程序。有没有人曾经尝试过这个,并且知道为什么会这样做?

在此先感谢
Ashish Shridharan
-----Original Message-----
Hi All
I have been trying to add a control to the header cell of
a datagrid on my ASP.NET page. These controls are defined
in the HTML as ASP.NET web controls.
They are being added into the header of the datagrid in
the "ItemDataBound" method of the grid. However, once,
they are added in the grid, i seem to lose the event
handler for the same control. Is there anyone who has
tried this before and knows why this is hapenning ??

Thanks in Advance
Ashish Shridharan
.



是的,我猜对了,这就是为什么我也在html中定义了

那些控件作为独立的web服务器

控制。我在

数据网格的ItemDataBound中所做的就是将这些控件放在标题中。


现在页面会回复每个控件。看起来很像b $ b我必须设置一个不同的机制来计算

哪个控制回来了。任何想法??

Yes, i guessed as much, which is why i have also defined
those controls in the html as independent web server
controls. All i am doing in the ItemDataBound of the
datagrid is positioning those controls in the header.

Now the page posts back for each of these controls. looks
like i''ll have to set up a different mechanism to figure
out which control posted back. Any ideas ??

-----原始消息-----
是的,我做过类似的事情。这是一种痛苦。

你'正在'失去'你的事件处理程序,因为控件是动态的,如果你做回发,它不知道
控件是否存在,即使它可能在viewstate中。

你将不得不在OnInit中重新创建控件。
-----Original Message-----
Yes, I have done something like that. It is a PAIN.

You''re "losing" your event handler because the control is
dynamic and if you do a postback it doesn''t know that the
control exists, even though it may be in the viewstate.

you will have to recreate the control in the OnInit.
-----原始消息-----
大家好我
我一直在努力将控件添加到我的ASP.NET页面上的标题单元
ofa datagrid。这些控件是作为ASP.NET Web控件在HTML中定义的

它们被添加到数据网格的标题中的ItemDataBound中。网格的方法。但是,有一次,它们被添加到网格中,我似乎失去了同一控件的事件处理程序。有没有人曾经尝试过这个,并且知道为什么会这样做?

在此先感谢
Ashish Shridharan
-----Original Message-----
Hi All
I have been trying to add a control to the header cell ofa datagrid on my ASP.NET page. These controls are definedin the HTML as ASP.NET web controls.
They are being added into the header of the datagrid in
the "ItemDataBound" method of the grid. However, once,
they are added in the grid, i seem to lose the event
handler for the same control. Is there anyone who has
tried this before and knows why this is hapenning ??

Thanks in Advance
Ashish Shridharan
.




您可能需要在

表单中添加HtmlInputHidden控件。编写一个JavaScript函数并将其连接到控件的

OnClick事件。在JavaScript中,将HtmlInputHidden控件的

值设置为单击的

控件的ID。然后当你在PostBack上重新创建

时,你会知道点击了什么控件

,你的应用程序将知道接下来该做什么。
you might need to add a HtmlInputHidden control to your
form. Write a JavaScript function and hook it up to the
OnClick event of your control. In the JavaScript set the
value of the HtmlInputHidden control to be the ID of the
control that was clicked. Then when you recreate
everything on PostBack you will know what control was
clicked and your app will know what to do next.
-----原始消息-----
是的,我猜到了,这就是为什么我也将html中的那些控件定义为独立的web服务器
控件。我在
数据网格的ItemDataBound中所做的就是将这些控件放在标题中。

现在页面会回复每个控件。看起来好像我必须建立一个不同的机制来确定哪个控制回来了。任何想法??

-----Original Message-----
Yes, i guessed as much, which is why i have also defined
those controls in the html as independent web server
controls. All i am doing in the ItemDataBound of the
datagrid is positioning those controls in the header.

Now the page posts back for each of these controls. looks
like i''ll have to set up a different mechanism to figure
out which control posted back. Any ideas ??

-----原始消息-----
是的,我做过类似的事情。这是一种痛苦。

你'正在'失去'你的事件处理程序,因为控件
-----Original Message-----
Yes, I have done something like that. It is a PAIN.

You''re "losing" your event handler because the control is
动态,如果你做回发,它不知道
控件是否存在,即使它可能在视图状态。

你必须在OnInit中重新创建控件。
dynamic and if you do a postback it doesn''t know that thecontrol exists, even though it may be in the viewstate.

you will have to recreate the control in the OnInit.
-----原始消息-----
大家好
我一直在尝试在ASP.NET页面上的数据网格的标题单元格
-----Original Message-----
Hi All
I have been trying to add a control to the header cell


中添加一个控件。这些控件在HTML中被定义为ASP.NET Web控件。
它们被添加到数据网格的标题中的ItemDataBound中。网格的方法。但是,有一次,它们被添加到网格中,我似乎失去了同一控件的事件处理程序。有没有人曾经尝试过这个,并且知道为什么会这样做?

在此先感谢
Ashish Shridharan


ofa datagrid on my ASP.NET page. These controls aredefinedin the HTML as ASP.NET web controls.
They are being added into the header of the datagrid in
the "ItemDataBound" method of the grid. However, once,
they are added in the grid, i seem to lose the event
handler for the same control. Is there anyone who has
tried this before and knows why this is hapenning ??

Thanks in Advance
Ashish Shridharan
.





这篇关于在DataGrid中添加动态控件时,事件处理程序丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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