C# ImageButton 事件未在更新面板内触发
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/534438/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ImageButton event not firing inside Update Panel
提问by Xaisoft
This is sort of a follow-up to my question here:
这是我的问题的后续:
Asp:Label is not shown when visible is set to true?
当visible 设置为true 时,不显示Asp:Label?
In the above question, I had a few controls where the visibility was not being set to false because they were not in an UpdatePanel
. Once I put the controls inside an UpdatePanel
, the toggling of visibility worked, but this has caused me another problem. I have an ImageButton
that exports to excel. When the button was not in an UpdatePanel
, the click event fired, but now that I put it inside an UpdatePanel
, the click event does not fire.
在上面的问题中,我有一些控件的可见性未设置为 false,因为它们不在UpdatePanel
. 一旦我将控件放在一个 中UpdatePanel
,可见性的切换就起作用了,但这给我带来了另一个问题。我有一个ImageButton
出口到 excel 的。当按钮不在 an 中时UpdatePanel
,点击事件被触发,但现在我把它放在 an 中UpdatePanel
,点击事件不会触发。
I also have a dropdown which works fine. I am thinking it has something to do with the fact that the ImageButton
does not have an AutoPostBack
property.
我也有一个工作正常的下拉菜单。我认为这与ImageButton
没有AutoPostBack
财产的事实有关。
采纳答案by Matthew Jones
Make sure that you have associated the Image Button to a PostBackTrigger on the UpdatePanel. If you are exporting to Excel using something similar to Matt Berseth's method, you have to have this trigger for the export to work.
确保您已将 Image Button 与 UpdatePanel 上的 PostBackTrigger 相关联。如果您使用类似于Matt Berseth 的方法导出到 Excel ,您必须使用此触发器才能导出工作。
<asp:PostBackTrigger ControlID="ImageButton1"/>
回答by teedyay
No, ImageButtons don't have AutoPostBack: they don't need them any more than regular buttons do.
不,ImageButtons 没有 AutoPostBack:它们不像普通按钮那样需要它们。
That behaviour sounds pretty weird. I'd say the first thing to try would be to change the asp:ImageButton into an asp:Button and see if that changes the behaviour. If not, the fact that it's an ImageButton is a red herring.
这种行为听起来很奇怪。我想说的第一件事是将 asp:ImageButton 更改为 asp:Button 并查看是否会改变行为。如果不是,那么它是 ImageButton 的事实就是一个红鲱鱼。
回答by BJLewies
Try replacing the imagebutton with a menu (which contains a single menu-item) and set the imageurl property thereof.
尝试用菜单(包含单个菜单项)替换 imagebutton 并设置其 imageurl 属性。
回答by Jose Freitas
myImagebutton.OnClientClick = "return true;";
回答by Russell
change the 'CausesValidation' attribute to false.
将“CausesValidation”属性更改为 false。
回答by hasitha
I had the similar problem. In my case, ImageButtons
are inside a repeater which is bound to a updatepanel
. But I used Page.RegisterRequiresRaiseEvent(ImageButton)
in the code behind within ItemDataBound
method of the repeater and it worked.
我有类似的问题。在我的情况下,ImageButtons
位于绑定到updatepanel
. 但是我Page.RegisterRequiresRaiseEvent(ImageButton)
在ItemDataBound
转发器的方法中使用了后面的代码并且它起作用了。
回答by Pete Smith
If you had a datalist with an imagebutton in the itemTemplate, the trigger is not required but causeValidation = false
is.
如果您在 itemTemplate 中有一个带有图像按钮的数据列表,则触发器不是必需的,而是必需causeValidation = false
的。
回答by Ni?u Alexandru
Add ChildrenAsTriggers="true"
to your update panel. Works if you have master pages.
添加ChildrenAsTriggers="true"
到您的更新面板。如果您有母版页,则可以使用。
If your update panel is in master you cannot add triggers.
如果您的更新面板在 master 中,则无法添加触发器。