用户控件中的 Asp.NET 下拉列表未触发 SelectedIndexChanged 事件

发布于 2024-08-23 11:16:30 字数 440 浏览 6 评论 0原文

Asp.Net 2.0 框架 - VB.Net 应用程序 我有一个包含 Asp.Net DropDownList 的 UserControl。

已经研究和\或尝试过的事情:

  • 如果不是Page.IsPostBack(仅加载一次),则控件会绑定到页面加载时的数据(仅加载一次)
  • 为控件设置ID属性(ID = ddlMyControl)
  • AutoPostBack设置为true
  • 设置控件上的EnableViewState将
  • UserControl 声明中的 AutoEventWireUp 设置为 true 将
  • 父页面中的 EnableEventValidation 设置为 false

无论我做什么,控件都不会触发其 SelectedIndexChanged 事件。帮助 !!

谢谢 :)

Asp.Net 2.0 framewrok - VB.Net application
I have a UserControl containing a Asp.Net DropDownList.

Things already researched and \ or tried:

  • The control gets bound to data on page load inside if not Page.IsPostBack (only loads once)
  • ID proprety is set for control (ID = ddlMyControl)
  • AutoPostBack is set to true
  • EnableViewState on the control is set to true
  • AutoEventWireUp in the UserControl declaration is set to true
  • EnableEventValidation is set to false in the parent page

The control will not fire it's SelectedIndexChanged event no matter what I do. HELP !!

Thanks :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

小傻瓜 2024-08-30 11:16:30

我遇到了类似的问题,这是因为我将 AutoPostBack="true" 排除在控制定义之外。在您原来的帖子中,您说您已经尝试过,但发布的代码:

<uc3:TheControl ID="ucMyControl" runat="server" />

不反映 AutoPostBack 属性。我将其添加到我的中,它解决了我的问题。希望有帮助。

I was running into a similar issue and it was because I left AutoPostBack="true" out of the control definition. In your original post, you said you had tried that but the posted code:

<uc3:TheControl ID="ucMyControl" runat="server" />

does not reflect the AutoPostBack property. I added that to mine and it took care of my problem. Hope that helps.

浪漫之都 2024-08-30 11:16:30

我知道已经很晚了,但我认为这会帮助其他面临同样问题的人。

我假设您想要触发已经与一些数据绑定的 DropDownListSelectedIndexChanged 事件!
例如[C#]

ddlMyDropDown.DataSource = listOfCustomers;
ddlMyDropDown.DataTextField = "CustomerName";
ddlMyDropDown.DataValueField = "CustomerID";
ddlMyDropDown.DataBind();
ddlMyDropDown.CauseValidation = false;

我假设您正在使用asp.net(最新版本)..也许是4.0。

I know it's very late but I thought it will help others who faced the same problem.

I'm assuming you want to fire the SelectedIndexChanged Event of a DropDownList which is already bound with some data!
For example [C#]

ddlMyDropDown.DataSource = listOfCustomers;
ddlMyDropDown.DataTextField = "CustomerName";
ddlMyDropDown.DataValueField = "CustomerID";
ddlMyDropDown.DataBind();
ddlMyDropDown.CauseValidation = false;

I'm assuming you are using asp.net (latest version).. maybe 4.0.

ㄟ。诗瑗 2024-08-30 11:16:30

那么“周边”页面呢?您可以在另一个页面中尝试您的用户控件吗?

如何添加事件处理程序?
如何纳入使用控制? (当通过代码时,可能太晚了?)

也许你可以显示一些代码;-)

What about the "surounding" page. You could try your UserControl within another page?

How do you add the event handler?
How do you include the use control? (When via code, may be to late?)

May be you could show some code ;-)

皇甫轩 2024-08-30 11:16:30

UserControl 不是动态加载的,而是在设计时在页面的 HTML 中添加到父页面中。

<uc3:TheControl ID="ucMyControl" runat="server" />

事件处理程序被编码在 UserContorl 本身的代码后面 - 标准内容:

 Protected Sub ddlMyThing_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlMyThing.SelectedIndexChanged
    'Do event stuff here.
End Sub

The UserControl is not being loaded dynamicaly but added to the parent page at design time in the HTML of the page

<uc3:TheControl ID="ucMyControl" runat="server" />

The event handler is codded in the code behind of the UserContorl itself - standard stuff:

 Protected Sub ddlMyThing_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlMyThing.SelectedIndexChanged
    'Do event stuff here.
End Sub
素年丶 2024-08-30 11:16:30

您是否设置了 ddl 的 onselectedindexchanged="ddlMyThing_SelectedIndexChanged" 属性?

Have you set the onselectedindexchanged="ddlMyThing_SelectedIndexChanged" property of the ddl?

很糊涂小朋友 2024-08-30 11:16:30

我认为您需要将 EnableEventValidation 设置为 True。

看看这个。

http://www.experts-exchange.com /Programming/Languages/.NET/ASP.NET/Q_22405007.html

希望这会有所帮助。

谢谢,

拉贾

I think you need to set EnableEventValidation to True.

Check this out.

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_22405007.html

Hope this helps.

Thanks,

Raja

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文