提交无效

时间:2012-11-07 10:25:14

标签: asp.net

我在ASP.NET应用程序中使用动态控件。所以问题是 - 当我单独使用这些控件时 - 它们运行良好。但是,当我将这两个控件放在同一页面上时 - 只会触发最后一次提交事件。任何人都可以帮我确定问题的位置以及解决方法吗?

这是我的aspx布局:

<%@ Control Language="C#" AutoEventWireup="True" CodeBehind="MYPAGE.ascx.cs" Inherits="MYNAMESPACE" %>
<%@ Register Assembly="MYANOTHERNAMESPACE" Namespace="MYNAMESPACE" TagPrefix="DAControl" %>

...
 <div>
     <DAControl:ChooseImageDialog runat="server" id="ChooseImageDialog" />
     <DAControl:ChooseVideoDialog runat="server" id="ChooseVideoDialog" />
 </div>

这是我的第一个控制:

    [ToolboxData("<{0}:ChooseImageDialog runat=server></{0}:ChooseImageDialog>")]
    public class ChooseImageDialog : WebControl
    {
        /* This is only part of my code, which should enough for explaining the issue*/

        private Button applyPreview = new Button();
        private Button cancelPreview = new Button();

        protected override void OnLoad(EventArgs e)
        {
            applyPreview.Click += new EventHandler(applyPreview_Click);

            base.OnLoad(e);
        }

        void applyPreview_Click(object sender, EventArgs e)
        {
            // I want to reach this block
        }
    }
}

这是我的第二个控件:

[ToolboxData("<{0}:ChooseVideoDialog runat=server></{0}:ChooseVideoDialog>")]
    public class ChooseVideoDialog : WebControl
    {
        /* This is only part of my code, which should enough for explaining the issue*/
        private Button applyVideoPreview = new Button();
        private Button cancelPreview = new Button();

        protected override void OnLoad(EventArgs e)
        {    
            applyVideoPreview.Click += new EventHandler(ApplyPreviewVideo_Click);

            base.OnLoad(e);
        }

        void ApplyPreviewVideo_Click(object sender, EventArgs e)
        {
            // I want to reach this block
        }

    }

1 个答案:

答案 0 :(得分:0)

必须在Init事件中连接事件。在生命周期的任何后期都为时已晚。