按钮没有在asp.net中触发

时间:2012-12-14 08:23:34

标签: c# asp.net events

我在asp.net页面中没有触发按钮时遇到问题,我想知道是否有人可以看到这个问题。

首先你需要知道的是我使用modalpopupexntender弹出面板,在最后一个面板上我开始动态地向现有面板添加控件。

以下是存在的面板和动态添加的控件

<asp:ModalPopupExtender ID="ModalPopupExtender10" runat="server" TargetControlID="hndPage5" OkControlID="imgExitEdit1"
    PopupControlID="pnlReview" BackgroundCssClass="LoadingBackground" >
</asp:ModalPopupExtender>

<input type="hidden" runat="server" id="hndPage5" />
<asp:Panel runat="server" ID="pnlReview" CssClass="Modal450h450w" Height="300px">
    This is table
</asp:Panel>

我从这段代码中开始向上面的面板添加控件此事件来自另一个带有按钮的modalpopupextender:

protected void btnReview_Button_Click(object sender, EventArgs e)
    {
HtmlTable table = new HtmlTable();

        DataTable tblBillingAddress = Members.MemberBillingAddressSearch(MemberID);

        for (int i = 0; i < tblBillingAddress.Columns.Count; i++)
        {
            CreateRow(tblBillingAddress.Columns[i].ColumnName.ToString(), tblBillingAddress.Rows[0][tblBillingAddress.Columns[i].ColumnName].ToString(), table);
        }

        Button btn = (Button)sender;

        if (btn.ID == "btnIbanReview")
        {
            CreateRow("thing", thing.Text, table);
            CreateRow("other", other.Text, table);

        }
        else if (btn.ID == "btnrrTReview")
        {
            CreateRow("this", this.Text, table);              
        }


        Button btnBack = new Button();
        Button btnConfirm = new Button();

        btnBack.ID = "btnReviewClose";
        btnConfirm.ID = "btnReviewConfirm";

        btnBack.Text = "Back";
        btnConfirm.Text = "Confirm";

        btnBack.Click += new EventHandler(this.btnAdd_Close_Click);
        btnConfirm.Click += new EventHandler(this.btnConfirm_Click);

        HtmlTableCell cell1 = new HtmlTableCell();
        HtmlTableCell cell2 = new HtmlTableCell();
        cell1.Controls.Add(btnBack);
        cell2.Controls.Add(btnConfirm);
        HtmlTableRow rr = new HtmlTableRow();

        rr.Cells.Add(cell1);
        rr.Cells.Add(cell2);

        table.Rows.Add(rr);


        pnlReview.Controls.Add(table);
        pnlReview.Visible = true;
        ModalPopupExtender10.Show();
}

这是CreateRow()方法:

private void CreateRow(string heading, string value, HtmlTable hTable)
    {
        HtmlTableRow row = new HtmlTableRow();
        HtmlTableCell cHeading = new HtmlTableCell();
        HtmlTableCell cValue = new HtmlTableCell();

        cHeading.InnerText = heading;
        cHeading.Style.Add("font-weight", "bold");
        row.Cells.Add(cHeading);                  
        cValue.InnerText = value;                
        row.Cells.Add(cValue);
        hTable.Rows.Add(row);            
    }

这是我创建的事件:

void btnConfirm_Click(object sender, EventArgs e)
    {
        ModalPopupExtender10.Hide();
    }

我已尝试在Page_Init(),Page_Onit()和Page_Load()中创建按钮,稍后我会在创建面板后添加控件。

任何帮助或在视线中都将受到赞赏

2 个答案:

答案 0 :(得分:0)

ModalPopupExtender有一个属性CancelcontrolID或类似的东西...... 如果您指定TargetControlID,那么也指定CancelControlID

答案 1 :(得分:0)

        <ajaxToolkit:UpdatePanel ID="UpdatePanel3" runat="server">
        <ContentTemplate>
            <asp:Button ID="fake2" runat="server" Style="display: none" />
            <Ajax:ModalPopupExtender ID="mpe_Mail" runat="server" BackgroundCssClass="modalBackground"
                TargetControlID="fake2" PopupControlID="pnl_Mail" CancelControlID="btn_Close">
            </Ajax:ModalPopupExtender>
            <asp:Panel ID="pnl_Mail" runat="server" Style="display: none;" CssClass="modalBackground1">
                <table width="350" border="0" align="center" cellpadding="0" cellspacing="0" style="background: #fff;">
                    <tr>
                        <div class="Lecture-Planform-headx">
                            <asp:Label ID="lbl_Employer" runat="server" />
                        </div>
                    </tr>
                    <tr>
                        <td align="center">
                            <div>
                                --This is table--
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="center">
                                <asp:Button ID="btn_Close" runat="server" CausesValidation="false" Text="Back" CssClass="activebutton2" OnClick="<--Add Your Function Hear-->" />
                            </div>
                        </td>
                    </tr>
                </table>
            </asp:Panel>
        </ContentTemplate>
    </ajaxToolkit:UpdatePanel>