将带有按钮的用户控件列表添加到占位符 - 没有事件?

发布于 2024-07-20 13:53:59 字数 532 浏览 6 评论 0原文

我想利用其中包含多个控制元素的“复杂”用户控件。 这与我将在列表中重复使用的控件相同,并且我已经为它准备了一个 PlaceHolder 控件。

我可以使用 LoadControl(path to .ascx) 添加控件 - 没问题。

我也可以通过自定义属性获取/设置访问嵌入的标签,这样我就可以完美地初始化每个控件。

但是当添加 LinkBut​​tons 时,我遇到了麻烦/问题。

当我单击该按钮时,我确实得到了呈现控件的页面的“提交”信息; 但控件自己的按钮事件似乎没有触发(或者至少父页面上的 PageLoad 似乎首先触发?) - 我无法弄清楚我的事件去哪里或在哪里查找名称/ID 或参数按钮。

为什么或者我在这里做错了什么?

我现在通过使用标签 more 和带有 URL 中 ID 的“硬编码 A HREF”制作了一个“假按钮”,但我想了解我需要捕获什么事件以及在何处或如何初始化按钮,因为我希望能够对这些用户控件使用“默认 ASP.NET”控件(希望没有太多的拼凑编码)...

I want to make use of "complex" usercontrols with more than one control element within. It's the same control I will reuse in the list, and I have a PlaceHolder control for it already.

I can add the control with LoadControl(path to .ascx) - no problem.

I can through my custom properties get/set access the embedded Labels, too, so I can initialize each control perfectly.

But when adding LinkButtons, I get into trouble/problems.

When I click the button, I do get a "submit" of the page rendering the controls; but the control's own button event does not seem to fire (or at least PageLoad on the parent page seems to fire first?) - I can't figure out where my event goes or where to look for a name/ID or parameter for this button.

How come or what am I doing wrong here?

I've made a "fake button" now by using a label more with a "hardcoded A HREF" with an ID in the URL, but I would like to learn what event I need to catch and where or how to init the button, because I want to be able to use "default ASP.NET" controls for these usercontrols (hopefully without too much patchwork-coding)...

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

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

发布评论

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

评论(1

人生百味 2024-07-27 13:53:59

事件“丢失”的唯一原因是您的控件没有以 ASP.Net 在回发后将事件与控件关联的方式重新创建。 它通过使用 ID 属性来实现这一点。

换句话说,您做错了三件事之一:

1)您在回发后 Init 中的创建阶段以不同的方式分配链接按钮的 ID

2)您正在使用代码动态创建链接按钮,但是您'在页面生命周期的 Init 阶段之后执行此操作,以便您的控件不参与 ViewState。

3)您在每次回发时重新绑定包含链接按钮的父控件的数据源。 使用 if (!IsPostBack) 来防止每次都重新绑定。

不幸的是,在没有看到您的代码的情况下,我无法提供比这更具体的内容。

The only reason that events get "lost" is because your controls are not being recreated in such a manner that ASP.Net can associate the event with the control after the postback. It does so through the use of the ID property.

In other words, you're doing one of three things wrong:

1) You're assigning the ID's of your linkbuttons differently during the creating phase in Init after the postback

2) You're creating your linkbuttons dynamically using code, but you're doing it after the Init phase of the page lifecycle, so that your controls do not participate in ViewState.

3) You're re-binding the datasource of the parent control containing the linkbuttons on every postback. Use if (!IsPostBack) to prevent rebinding it every time.

Without seeing your code I can't give anything more specific than that unfortunately.

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