ModalPopup div不显示

时间:2013-03-05 21:48:50

标签: asp.net listview html popup modal-dialog

我的asp.net应用程序中有一个ModalPopup窗口,我希望在单击Listview控件项时显示该窗口。

 <div id="ModalPopup" style="visibility:hidden" runat="server">
  <div style="position: absolute; width: 100%; height: 100%; z-index: 10002; background-color: Gray; filter: alpha(opacity=70); opacity: 0.7;">
    &nbsp;
  </div>
  <table style="position: absolute; width: 100%; height: 100%; z-index: 10003;">
    <tr>
      <td align="center" valign="middle">
        <div style="color: Black; font-weight: bolder; background-color: White; padding: 15px; width: 200px;">
          <asp:Image ID="Image4" runat="server" ImageUrl="~/Images/ajax-loader.gif" />...Processing....
        </div>
      </td>
    </tr>
  </table>
  </div>  

但是,在我的RadListView1_SelectedIndexChanged事件中,我的代码是:ModalPopup.Attributes.Add("style", "visibility:visible");,但模式弹出窗口不会显示。

如何在选择ListView项目时显示它?

1 个答案:

答案 0 :(得分:1)

由于您已将ModalPopup div定义为服务器控件(例如runat=server ,因此您要确定是否在代码隐藏中显示或不显示 - 只需使用Visible属性...

 <div id="ModalPopup" Visible="false" runat="server">
   ....
 </div>

在代码后面的RadListView1_SelectedIndexChanged事件中,只需更改为Visible为true:

protected void RadListView1_SelectedIndexChanged()
{
    ModalPopup.Visible = true;
}

如果您坚持要更改可见性属性本身,可以像这样使用 RegisterStartupScript

protected void RadListView1_SelectedIndexChanged()
{
    ClientScript.RegisterStartupScript(this.GetType(), "ShowPopup", "document.getElementById('" + ModalPopup.ClientID + "').style.visibility = 'visible';", true);
}