按钮单击“事件未触发”

时间:2011-08-23 19:57:49

标签: c# asp.net user-controls

需要一些帮助。

描述: 我有一个从DataGrid Add New命令启动的WorkFlow Type UserControl。 UserControl的第1步允许用户输入一些搜索条件,单击Next Button,它将显示动态创建的UserControl(步骤2),显示检索到datagrid的数据行。然后,用户选择他们想要为新条目建模的行,并单击srNextButton以转到最终的数据输入屏幕。

问题: 动态创建的用户控件上的srNextButton(步骤2)不会触发按钮事件处理程序代码,也不会导致任何类型的回发。我做错了什么?

UserControl Step2:

    <div style="width: 1000px; height: 400px; overflow: scroll;">
        <telerik:RadGrid ID="grd1" runat="server" CellSpacing="0" GridLines="None">
            <headercontextmenu cssclass="GridContextMenu GridContextMenu_Default">
    </headercontextmenu>
            <mastertableview tablelayout="Auto" width="95%">
        <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
            <HeaderStyle Width="20px"></HeaderStyle>
        </RowIndicatorColumn>
        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
            <HeaderStyle Width="20px"></HeaderStyle>
        </ExpandCollapseColumn>
        <EditFormSettings>
            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
            </EditColumn>
        </EditFormSettings>
    </mastertableview>
            <clientsettings>
        <Selecting AllowRowSelect="True" />
    </clientsettings>
            <filtermenu enableimagesprites="False">
    </filtermenu>
        </telerik:RadGrid>
        <asp:Button runat="server" ID="srNextButton" OnClick="nextButton_Click" Text="Next"
            CssClass="nextButton" AutoPostBack="true" />
        <asp:Button runat="server" ID="btnCancel" OnClientClick="CancelEdit()" Text="Cancel"
            CssClass="nextButton" />
    </div>

代码第2步:

    protected void nextButton_Click(object sender, EventArgs e)
    {
        GridIndexCollection _int = this.grdPolicyCoverage.SelectedIndexes;
        GoToNextItem(this);
    }

我也尝试添加:

    protected override void OnInit(EventArgs e)
    {

        base.OnInit(e);
        this.PreRender += SearchResults_PreRender;

        if (!IsPostBack)
        {
            this.srNextButton.Click += new EventHandler(nextButton_Click);
        }

    }

我有一个BaseUserControl.cs,它包含控件的加载

    protected void GoToNextItem(Control control)
    {

        //RadPanelBar _radPanelBar = (RadPanelBar)page.Page.FindControl("RadPanelBar1");
        //NewAdjustment _newAdjustment = (NewAdjustment)this.Page.FindControl() 
        RadPanelBar _radPanelBar =
            (RadPanelBar) control.Parent.Parent.Parent.Parent.Parent.FindControl("RadPanelBar1");

        int selectedIndex = _radPanelBar.SelectedItem.Index;

        if (selectedIndex == 1)
        {
            RadPanelItem _pnlSearchResults = (RadPanelItem)_radPanelBar.FindItemByValue("SearchResults");
            _pnlSearchResults.Controls.Add(LoadControl("~/Controls/AdjustmentWorkFlow/SearchResults.ascx"));

        }
        _radPanelBar.Items[selectedIndex + 1].Selected = true;
        _radPanelBar.Items[selectedIndex + 1].Expanded = true;
        _radPanelBar.Items[selectedIndex + 1].Enabled = true;
        _radPanelBar.Items[selectedIndex].Expanded = false;


    }

父UserControl开始时它下面的每个控件都在RadAjaxPanel中,如果这有所不同的话。

1 个答案:

答案 0 :(得分:0)

只需尝试删除代码:

this.srNextButton.Click += new EventHandler(nextButton_Click);

来自问题中的OnInit并将其放在Page_Load事件处理程序中,而不检查IsPostBack。

现在怎么样? :)