English 中文(简体)
强制在每次回发时为自定义控件激发事件处理程序
原标题:Force an event handler to fire for a custom control on every postback
  • 时间:2011-02-11 20:22:47
  •  标签:
  • asp.net

我怀疑我的问题围绕着对自定义事件处理程序在ASP.NET中如何工作的理解不足。我读过几篇文章,但目标受众一直在尝试与我不同的东西。

我已经创建了一个UserControl,它在Init事件期间动态地放置在我的页面上。它的填充和工作都很好,但在回发期间如何从中检索数据让我绞尽脑汁。

它实际上是一个多pick组合框,完全使用客户端JavaScript进行操作(我大量使用jQuery)。在控件容器元素中,我呈现一个空的DIV元素,该元素包含所有选定的项。当用户选择项目时,我在包含一些标记的容器DIV中生成DIV。在服务器端,我感兴趣的是几个INPUT字段的内容。

选择一个项目后,呈现的HTML看起来像:

<div class="multiPickContainer">
  <div class="multiPickItem">
    <input type="text" />
    <input type="hidden" />
  </div>
</div>

当然,问题是这些选择的项目是在客户端生成的,而服务器对此一无所知(例如,没有runat=“server”,这是纯HTML)。

在任何帖子[返回]中,我都希望在我的自定义控件中触发一个事件处理程序,使我能够检查此容器DIV中有哪些元素。我希望无论用户是否进行了任何选择(控件可能已预填充,在这种情况下,我仍然想知道其中有哪些选择)都能触发此事件。

我想要的是这样的东西:

private GenerateControl(TemplateControl page){
  var control = page.LoadControl("~/MyControl.ascx") as MyControl;
  control.OnPostBack += HandlePostback;
}

我可能完全偏离了轨道,这可能实际上是不可能的(或者是一个愚蠢的想法)。我能想到的唯一替代方案是发出实际的ASP.NET控件并挂接内置的事件处理程序。

有人能提出任何建议吗?或者给我介绍一下关于创建自定义事件处理程序的任何好的文献吗?

最佳回答

如果您给输入一个名称属性,这些值将显示在请求中。表单

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签