ModalPopUp不会在按钮点击时隐藏

时间:2014-08-10 14:19:06

标签: c# asp.net ajaxcontroltoolkit

使用RadioButtonList选择输入数据的选项,其中一个是AJAX ModalPopUp中的gridview。当用户单击ModalPopUp中的按钮时,ModalPopUp需要隐藏。虽然只是在某一点上,但这并不起作用。代码如下所示。我认为这是一个简单的事情,但我已经审查了很多其他帖子而没有成功:

单选按钮列表:

<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
  <asp:ListItem Selected="True">Manual Entry (separate with semi-colons)</asp:ListItem>
  <asp:ListItem>Artists Only</asp:ListItem>
  <asp:ListItem>Clients Only</asp:ListItem>
  <asp:ListItem>Test with a gridview</asp:ListItem>
 </asp:RadioButtonList>

ModalPopUp中的Gridview:

<asp:UpdatePanel runat="server">
  <ContentTemplate>
    <asp:HiddenField runat="server" ID="ModalHidden" />
      <ajax:ModalPopupExtender ID="George" runat="server" TargetControlID="ModalHidden" PopupControlID="PopUpPanel" DropShadow="true" CancelControlID="btnCancel" PopupDragHandleControlID="Select Emails" Drag="true">
      </ajax:ModalPopupExtender>
      <br>
      </br>
      <br>
      </br>
      <asp:Panel ID="PopUpPanel" runat="server" BorderColor="Black" BackColor="LightGray" BorderStyle="Solid" BorderWidth="10px">

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource3">
          <rowstyle backcolor="LightCyan" forecolor="DarkBlue" font-italic="true"/>
            <alternatingrowstyle backcolor="PaleTurquoise" forecolor="DarkBlue" font-italic="true"/>      
              <Columns>
                <asp:TemplateField>
                  <ItemTemplate>
                    <asp:CheckBox ID="ckboxGridview" runat="server"></asp:CheckBox>
                  </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" Visible="false"/>

                <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
                <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
                <asp:BoundField DataField="EmailAddress" HeaderText="EmailAddress" SortExpression="EmailAddress" />
            </Columns>
          </asp:GridView>
          <br>
          </br>

          <asp:Button ID="btnSelectGVAddresses" runat="server" Text="Select Addresses" OnClick="btnOK_Click" />
          <asp:Button ID="btnCancel" runat="server" Text="Cancel" />

          <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:C:\........ %>" SelectCommand="SELECT * FROM [tbl_Op_Recipients]"></asp:SqlDataSource>

        </asp:Panel>
        <br>
        </br>
      </ContentTemplate>
    </asp:UpdatePanel>

RadioButtonList的代码:

protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
    TextBox temp_sent = frmSendEmail.FindControl("sent_toTextBox") as TextBox;

    RadioButtonList temp_radio = frmSendEmail.FindControl("RadioButtonList1")
as RadioButtonList;

    if (temp_radio.SelectedItem.Text == "Artists Only")
    {
        temp_sent.Text = "All Artists";
        frmSendEmail.FindControl("EmailAddressesForEmail").Visible = false;
        frmSendEmail.FindControl("PopUpPanel").Visible = false;

        string sqlquery = @"SELECT EmailAddress, ISNULL(FirstName, 'Artist') AS           EmailName FROM tbl_Op_Recipients WHERE EmailAddress IS NOT NULL AND UserType = 'A'";

        gather_emails(sqlquery);

    }

    if (temp_radio.SelectedItem.Text == "Clients Only")
    {
        temp_sent.Text = "All Clients";
        frmSendEmail.FindControl("EmailAddressesForEmail").Visible = false;
        frmSendEmail.FindControl("PopUpPanel").Visible = false;  

        string sqlquery = @"SELECT EmailAddress, ISNULL(FirstName, 'Client') AS     EmailName FROM tbl_Op_Recipients WHERE EmailAddress IS NOT NULL AND UserType = 'C'";

        gather_emails(sqlquery);

    }

    if (temp_radio.SelectedItem.Text == "Manual Entry (separate with semi-colons)")
    {
        frmSendEmail.FindControl("EmailAddressesForEmail").Visible = true;
        temp_sent.Text = "Enter Names and Emails Manually";
        frmSendEmail.FindControl("PopUpPanel").Visible = false;  


    }


    if (temp_radio.SelectedItem.Text == "Test with a gridview")
    {
        temp_sent.Text = "Select multiple items from popup";
        frmSendEmail.FindControl("EmailAddressesForEmail").Visible = false;

        frmSendEmail.FindControl("PopUpPanel").Visible = true;

        ModalPopupExtender test = frmSendEmail.FindControl("George") as     ModalPopupExtender;
        test.Show();

        Response.Write("breakpoint 291");

    }



    if (temp_radio.SelectedItem.Text == null )
        temp_radio.Text = "";




}

Gridview的代码隐藏(隐藏modalpopup):

protected void btnOK_Click(object sender, EventArgs e)
{

    Panel PanelTemp = frmSendEmail.FindControl("PopUpPanel") as Panel;
    PanelTemp.Visible = false;

    RadioButtonList tempRadioButton = frmSendEmail.FindControl("RadioButtonList1") as     RadioButtonList;

    tempRadioButton.Items[0].Selected = true;


    ModalPopupExtender PopUpTemp = frmSendEmail.FindControl("George") as ModalPopupExtender;
    PopUpTemp.Hide();


    GridView GVTemp = frmSendEmail.FindControl("Gridview1") as GridView;

    var list = new List<EmailAddresses>();

    foreach(GridViewRow row in GVTemp.Rows)
    {
        CheckBox ChkBoxtmp = row.FindControl("ckboxGridview") as CheckBox;

        if(ChkBoxtmp.Checked)
        {


        list.Add(new EmailAddresses { EmailAddress = row.Cells[4].Text, FirstNames = row.Cells[2].Text });
        }
    }

    EmailAddresses[] allRecords = list.ToArray();


    btnSend_Click(allRecords);

}

2 个答案:

答案 0 :(得分:0)

我们在实现ajax弹出窗口时遇到了几个问题。最后,我们实现了一个不需要ajax / javascript / jquery / update panel / css技巧的解决方案。 这对我们来说大约有一个月左右的时间。你可能想看看: A modal popup with out using ajax, update panel, jquery or javascript- surprisingly this seems to work

由于

答案 1 :(得分:0)

我添加了一个链接来下载任何人都可以尝试的源代码。 http://02e34b5.netsolhost.com/youtube/Zpopup.aspx 感谢