ASP.NET 动态 RadioButton 的 AutoPostBack 属性在回发后未设置
我在 Page_Init 期间动态创建了一系列 RadioButtons 和其他控件。如果 RadioButton 满足某些条件,我会将其设置为 AutoPostBack,以便调用事件处理程序。这在初始加载时工作得很好,但从回发重新加载页面后,RadioButton 不再设置为 AutoPostBack。
如果组中的所有单选按钮都设置为 AutoPostBack,则这似乎有效,但我只希望特定的单选按钮(通常是“其他”选择)执行此操作。有没有办法可以在不将其余人员设置为组的情况下执行此操作?
I have a series of RadioButtons and other controls dynamically created during Page_Init. If a RadioButton meets some condition, I have it set to AutoPostBack so an event handler will be called. This works fine with the initial load, but after the page is reloaded from the post back, the RadioButton is no longer set to AutoPostBack.
This appears to work if all RadioButtons in the group are set to AutoPostBack, but I only want the specific one (typically an "Other" selection) to do that. Is there a way I can do this without setting the rest in the group?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Page_Init 在 ViewState 加载之前被触发。因此,还没有控件会更新其值以反映 ViewState。
您是否在 Page_Init 中执行任何依赖于页面上可设置的值的操作?例如,您是否想查看用户是否单击了特定的单选按钮?如果是这样,您需要在页面生命周期的后期、ViewState 加载后(例如 OnPreLoad)执行此操作。
一旦您全神贯注于,您将更加享受 ASP.NET 开发的乐趣页面生命周期。干杯!
Page_Init is fired before the ViewState is loaded. Therefore, no controls will have their values updated to reflect the ViewState yet.
Are you doing anything in your Page_Init which is dependent on any values settable on the page? For example, are you looking to see whether the user has clicked a particular radio button? If so, you'll need to do so later in the page lifecycle, after the ViewState has been loaded (OnPreLoad, for example).
You'll enjoy ASP.NET development a LOT more, once you wrap your brain around the Page Lifecycle. Cheers!