在动态的onLoadComplete添加LinkBut​​tons ClickEvent [英] Adding ClickEvent on dynamic LinkButtons in OnLoadComplete

查看:214
本文介绍了在动态的onLoadComplete添加LinkBut​​tons ClickEvent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建在ASP.Net一个文件浏览器,但我遇到了我认为涉及到动态控件的事件wireing一个问题。我要解释一下我的code在这里所做的:

I'm creating a file-browser in ASP.Net but I have run into a problem which I believe relates to event-wireing on dynamic controls. I'll explain what my code does here:

在我的页面加载(onLoad)实现,我调用一个方法(createStuff()),创造(在当前目录下再presenting文件夹)的一些linkbuttons,它们被连接到改变当前目录到一个事件一个是与LinkBut​​ton的相关联

When my page loads (OnLoad) i call a method (createStuff()) that create a number of linkbuttons (representing folders in a current directory) which are wired to an event that changes the current directory to the one that is associated with the linkbutton.

由于一个LinkBut​​ton单击事件的OnLoad之后触发被称为(和当前目录因此onload事件后首先改变)的linkbuttons不会更新以反映新的当前目录(它们是在当前目录改变之前创建通过点击事件)。因此,我也呼吁createStuff()中的onLoadComplete导致被更新的linkbuttons和反映了文件夹中的新的当前目录。

Since a linkbutton-click-event is fired after OnLoad is called (and the current directory therefore is first changed after onload) the linkbuttons doesn't update to reflect the new current directory (they are created before the current directory is changed by the click-event). Therefore I also call createStuff() in OnLoadComplete resulting in the linkbuttons being updated and reflecting the folders in the new current directory.

但是,(这是我的问题),似乎事件wireing(点击+ =新的EventHandler(changeDirectory))我createStuff做()并未真正发挥作用的时候方法的onLoadComplete被调用(是的onLoadComplete之后调用一个LinkBut​​ton单击事件已经被解雇)。其结果是,虽然linkbuttons的文本属性反映在新目录中的文件夹点击linkbuttons不火的事件。

HOWEVER (and this is my problem) it seems that the event wireing (Click += new EventHandler(changeDirectory)) I do in createStuff() doesn't really work when the method is called in OnLoadComplete (OnLoadComplete is called after a linkbutton-click-event has been fired). The result is that while the text-property of the linkbuttons reflect the folders in the new directory clicking the linkbuttons doesn't fire the event.

我怎样才能解决这个问题呢?我试着rewireing上的OnLoad,但相同的结果LinkBut​​tons的事件。

How can I fix this problem? I tried rewireing the events on the LinkButtons in OnLoad but same result.

感谢您提前

西蒙,丹麦

推荐答案

设置LinkBut​​ton的 ID 属性一致。

Set the LinkButton's ID property consistently.

此行为两个常见的原因是:(1)缺少的事件处理程序和(2)缺少的ID属性。既然你确定你的事件处理过程中的OnLoad附着则缺少的ID属性是可能的罪魁祸首。

Two common causes of this behavior are (1) missing event handlers and (2) missing ID properties. Since you're sure that your event handler is being attached during OnLoad then missing ID properties is the likely culprit.

当用户点击客户端上你的LinkBut​​ton,一个回发发送到服务器,它通过ID名称LinkBut​​ton的。如果你不确保你的控件回发事件处理程序可能不被加注之间相同的ID。

When a user clicks your LinkButton on the client, a PostBack is sent to the server which names the LinkButton by ID. If you're not ensuring that your control has the same ID between PostBacks your event handler might not get raised.

这篇关于在动态的onLoadComplete添加LinkBut​​tons ClickEvent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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