About Popup Window in ASP.Net

2020-07-08 05:58发布

问题:

I have a gridview which contains a details button as the last column.

My aspx:

<asp:GridView Width="100%" ID="gv_NotApplied" CssClass="datatable" AllowSorting="True"
    runat="server" TabIndex="2" AutoGenerateColumns="False" AllowPaging="True" GridLines="None">
    <Columns>
        <asp:TemplateField HeaderText="serial">
            <ItemTemplate>
                <asp:Label ID="lblSerial" runat="server"></asp:Label>

            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField HeaderText="name" DataField="crs_name" />
        <asp:BoundField HeaderText="lecturer" DataField="name" />
        <asp:TemplateField HeaderText="details">
            <ItemTemplate>
                <asp:ImageButton ID="Ibtn_Details" runat="server" ImageUrl="~/Images/detail.png"
                    CommandArgument='<%#((GridViewRow)Container).RowIndex%>' CommandName="Detail"
                    CausesValidation="false" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <RowStyle VerticalAlign="Top" CssClass="row" />
</asp:GridView>

What I would like to do is:

  • When the user clicks the details button, open a pop up window (dialog window).

  • In this window I would like to put some asp.net server controls in (like grid views). So I want this window to enable/allow me to access those controls in the code behind.

回答1:

I suggest that you open a modal pop up window like colorbox and this color box can point to show an aspx page that contain all the controls that you want. The color box will tell you how to make your button open the modal window and how to put in it the page.



回答2:

For this kind of thing I love the following construct:

<asp:UpdatePanel id="UpdatePanel1" runat="server">
  <ContentTemplate>
    <asp:Panel id="popup" visible="false" runat="server">
      popup Content
    </asp:Panel>

    <asp:AlwaysVisibleControlExtender ID="AlwaysVisibleControlExtender1" TargetControlID="popup" runat="server" />
    <asp:DragPanelExtender ID="DragPanelExtender1" TargetControlID="popup" runat="server" />
  </ContentTemplate>
 </asp:UpdatePanel>
  • Like this you can set popup.visible = true; when you need the popup and have full control over its contents.
  • The Updatepanel + Ajax Control Toolkit Extender will give it the look and feel of an independant popup, though.


回答3:

Create your desire aspx popup and add javascript event to the button. For example:

<button onclick="window.open('_blank', 'www.google.co.il', 'width=100,height=100');">asdasd</button>

You can put the event using the code behind and not direct on the aspx in order to give different url for each button.
In order to find the controls in the item tamplate read here:

http://forums.asp.net/t/998368.aspx/1?Frustated+of+FindControl+FindControl+in+GridView+s+ItemTemplate