0

我在运行时创建一个按钮,点击它我想打开一个 ajax 模型弹出窗口。但我无法将模型弹出窗口的目标控件 ID 设置为此运行时创建的按钮 ID。有人可以建议我如何实现这一目标吗?或任何替代方式存在?

我的代码如下。这就是我创建运行时按钮的方式。

 protected void grdSurveyMaster_ItemCreated(object sender, GridItemEventArgs e)
    {

        if (e.Item is GridFooterItem)
        {
            GridFooterItem footerItem = (GridFooterItem)e.Item;
            // RadScriptManager1.RegisterAsyncPostBackControl(btn);
            Button btn = new Button();
            btn.Text = "Take a new survey";
            btn.CommandName = "newAssess";
            btn.Click += new System.EventHandler(grdMasterbtnClick);
            footerItem.Cells[2].Controls.Add(btn);
            //ModalPopupExtender1.TargetControlID = "btn";// Convert.ToString(Page.FindControl(Convert.ToString(btn.ClientID)));

        }
    }

以下是我的 HTML

<asp:UpdatePanel ID="updatepanel1" runat="server">
        <ContentTemplate>
            <cc1:ModalPopupExtender CancelControlID="btnCancel" PopupControlID="modelPopUp" ID="ModalPopupExtender1"
                runat="server" TargetControlID="btnDefault">
            </cc1:ModalPopupExtender>
            <asp:Button ID="btnDefault" runat="server" Visible="false" />
            <asp:Panel ID="modelPopUp" runat="server" Visible="false" BackColor="AliceBlue">
                <p>
                    These items will be permanently deleted and cannot be recovered. Are you sure?
                </p>
                <asp:Button ID="btnOk" Text="OK" runat="server" />
                <asp:Button ID="btnCancel" Text="Cancel" runat="server" />
            </asp:Panel>
        </ContentTemplate>
    </asp:UpdatePanel>
4

1 回答 1

1

好吧,您将 Popup 的 TargetControl 设置为一个不可见的未使用按钮是正确的。现在显示/隐藏弹出窗口的最佳方法是使用 Javascript。为此,您必须设置 ModalPopupExtender 的 behaviorid="someString" 并创建一个像这样的 javascript 函数:

function ShowModalPopup(behaviourId) {
$find(behaviourId).show();
}

然后您可以将 javascript 函数分配给一个按钮:

btn.OnClientClick = String.Format("ShowModalPopup('{0}')", 
    ModalPopupExtender1.behaviorid);
于 2012-05-23T07:30:58.013 回答