动态地添加用户控件不选择更改触发回发事件? [英] Dynamically added UserControl not firing PostBack event on selection change?

查看:91
本文介绍了动态地添加用户控件不选择更改触发回发事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我们动态加载一个asp.net网页(.NET 2.0)上的用户控制一个很奇怪的问题。用户控件有3个下拉菜单,其中一个附加了一个SelectedIndexChanged事件(与一组值的加载第三个下拉菜单)。

奇怪的是,如果目前有任何无效的字段(其中字段验证已激活)形式的其他部分,当你去选择下降的问题倒在它什么也不做第一个变化,但随后当您再次更改索引它完美!我不明白怎么事件不会火第一个变化,但对于每一个变化之后。

但是,如果所有这些字段填写正确的用户控件上面,它正确触发了SelectedIndexChanged事件。

在关于验证我已经停用​​所有可能的验证,以尝试和消除它作为一个罪魁祸首,所以我不知道如何验证可以影响用户控件。

任何帮助将大大AP preciated:)


解决方案

  1. 如果您不想验证在第一个下拉的selectionIndexChange形式,简单的附加属性 CauseValidation =FALSE,它不会开火selectionIndexChange表单验证


  2. 如果你(在运行时),请确保你没有做它在如果(!的IsPostBack)块,因为你必须添加动态添加控件甚至在回传控制为好。这取决于你如何添加控件,但一般这些都是常见的错误在处理这类问题


i have a very strange issue with a user control we are dynamically loading on an asp.net web page(.net 2.0). the user control has 3 dropdowns, one of which has a selectedindexchanged event attached to it (which loads the third dropdown with a set of values).

the weird thing is, if there are currently any invalid fields (where field validators have been activated) in other parts of the form, when you go to select the drop down in question on the FIRST change it does nothing, but then when you change the index again it works perfectly! i dont understand how the event wont fire for the first change, but for every change thereafter.

However, if all these fields are filled in correctly above the usercontrol, it fires off the selectedindexchanged event correctly.

in regards to validation i have disabled ALL POSSIBLE validation in order to try and eliminate it as a culprit, so i dont understand how validation can be affecting the usercontrol.

any help would be greatly appreciated :)

解决方案

  1. If you don't want to validate form on first dropdown's selectionIndexChange, simple add property CauseValidation="false" and it will not fire form validation on selectionIndexChange.

  2. If you are adding controls dynamically (at run time) make sure you are not doing it in the if(!IsPostBack) block because you have to add controls even on the postback as well. This depends on how you add controls but generally these are common errors while dealing with such kind of problem

这篇关于动态地添加用户控件不选择更改触发回发事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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