asp:ModalPopupExtender按钮导致主页上的回发

时间:2012-03-16 21:28:09

标签: asp.net modalpopupextender

我有一个页面,我正在尝试使用asp:ModalPopupExtender。我使用弹出窗口作为搜索工具,因此它具有用户控件,文本框,搜索按钮,网格视图和确定按钮。当用户输入搜索词并单击“搜索”按钮时,会发生导致弹出窗口关闭的回发。在用户单击“确定”按钮之前,我不会关闭弹出窗口。我可以完全按照没有其他功能的简单页面使用弹出窗口,它可以正常工作。我有点难过。

非常感谢任何帮助。

以下是包含弹出窗口的页面上的代码。

<asp:Panel ID="ApplicationPicker" runat="server" CssClass="hidden">
                                                <asp:Button ID="Button1" runat="server" Text="Search for Application" />
                                                <asp:Label ID="ApplicationID" runat="server"></asp:Label>
                                                <asp:Panel ID="Panel1" runat="server" CssClass="modalBackground" style="display:none;"> 
                                                    <appPicker:ApplicationPicker ID="thisAppPicker" runat="server" />
                                                    <asp:Button ID="btnOk" runat="server" Text="Ok" OnClick="OkButton_Clicked" /> 
                                                <asp:Button ID="btnClose" runat="server" Text="Close Me" /> 
                                                </asp:Panel> 

                                                <asp:ModalPopupExtender 
                                                DropShadow="true" 
                                                CancelControlID="btnClose" 
                                                runat="server" 
                                                PopupControlID="Panel1" 
                                                id="ModalPopupExtender1" 
                                                TargetControlID="Button1" /> 
                                            </asp:Panel>

这是应用程序选择器用户控件。整个过程都在更新面板中,但由于某些原因,这个编辑器正在弄乱代码格式,其中包含更新面板。

<asp:Panel ID="pDelegateBody" BackColor="White" runat="server">
<table>
    <tr>
        <td><asp:Label CssClass="indentedTextBold" ID="ApplicationSearchLabel" runat="server" Text="Search for:"></asp:Label></td>
        <td><asp:TextBox ID="txtSearch" runat="server" Width="300px" Visible="true" /><asp:Label ID="ValidationLabel" runat="server" Text="Please enter at least 3 characters to search." ForeColor="Red" Visible="false"></asp:Label></td>

        <td><asp:Button ID="btnSearch" runat="server" Text="Search" CssClass="Buttons" onclick="Search_Click" /></td>
    </tr>
    <tr>
        <td colspan="4">
        <asp:Panel ID="PanelProjectPicker" runat="server" Height="220px" Width="600px" ScrollBars="Vertical" BorderStyle="Solid" BorderWidth="1" BorderColor="GrayText">
            <telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="False" 
                AutoGenerateColumns="False" CellPadding="0" DataKeyNames="LANID" 
                EnableEmbeddedSkins="false" onitemcommand="RadGrid1_ItemCommand" 
                ShowHeader="true" Skin="WF" ViewStateMode="Enabled" Width="580px" ClientIDMode="AutoID">
                <MasterTableView Font-Size="X-Small">
                    <Columns>
                        <telerik:GridBoundColumn DataField="ApplicationID" HeaderText="ID" Visible="False" />
                        <telerik:GridBoundColumn DataField="Name" HeaderText="Display Name" SortExpression="DISPLAY_NAME" />
                    </Columns>
                </MasterTableView>
                <ClientSettings EnablePostBackOnRowClick="true" EnableRowHoverStyle="True">
                    <Selecting AllowRowSelect="true" />
                </ClientSettings>
                <HeaderStyle BackColor="#666666" Font-Names="verdana, arial" Font-Size="Small" 
                    Height="20px" />
            </telerik:RadGrid>
        </asp:Panel>
        <asp:Label ID="appID" runat="server"></asp:Label>
        </td>
    </tr>
</table>

以下是应用程序选择器背后的代码

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == "RowClick")
        {
            GridDataItem item = RadGrid1.Items[e.Item.ItemIndex];
            appID.Text = item["ApplicationID"].Text;
        }
    }
    protected void loadData()
    {
        if (Session["User"] != null)
        {
            currentUser = (User)Session["User"];
        }

        if (txtSearch.Text != "" && txtSearch.Text.Length > 2)
        {
            List<Application> AllApplications = new List<Application>();

            if (UserController.IsUserWOT((User)Session["User"]))
            {
                AllApplications = BusinessUtility.GetApplications();
            }
            else
            {
                AllApplications = BusinessUtility.GetApplicationsByManagerLanId(currentUser.LanID);
            }

            List<Application> filteredApplications = new List<Application>();

            filteredApplications = AllApplications.Where(x => x.Name.ToString().ToUpper().Contains(txtSearch.Text.ToUpper())).ToList();

            if (filteredApplications.Count > 0)
            {
                RadGrid1.DataSource = filteredApplications;
                RadGrid1.DataBind();
            }
        }
    }

    protected void Search_Click(object sender, EventArgs e)
    {
        if (txtSearch.Text.Length < 3)
        {
            ValidationLabel.Visible = true;
        }
        else
        {
            ValidationLabel.Visible = false;
            RadGrid1.DataSource = "";
            RadGrid1.DataBind();
            loadData();
            PanelProjectPicker.Visible = true;
        }
    }

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

在Search_Click的else条件中,您可以添加ModalPopupExtender1.show();