【问题标题】:asp.net ModalPopupExtender : need to show scroll bar when overflowasp.net ModalPopupExtender:溢出时需要显示滚动条
【发布时间】:2011-01-26 01:26:29
【问题描述】:

我在 ModalPopupExtender 中显示一个网格视图。 屏幕分辨率过小,弹窗过大,全部显示在页面上。

当这种情况发生时,我只想在弹出窗口中添加滚动条。

我知道这可能是一些 CSS,但我尝试的所有方法都不起作用。

这里是一些基本的 css

.modalTextBoxBackground
{
   background-color:Gray;
   filter:alpha(opacity=70);
   opacity:0.7;
}  
.modalTextBox
{
    border: 1px solid #FFFFFF;
    background-color: #0066CC;
    color: #00FFFF;

}

这里有一些来自 aspx 的代码

<asp:Panel ID="OptionSelectionPanel" runat="server" CssClass="modalTextBox">
            <asp:UpdatePanel ID="OptionSelectionUpdatePanel" runat="server" UpdateMode="Conditional" >
            <Triggers>
                <asp:asyncPostBackTrigger ControlID="TemplateSelection" />
            </Triggers>
            <ContentTemplate>

            <table class="EditRow">
            <tr class="HeaderFooter">
            <td colspan="3" class="modalTextBoxTitle">
                Add options to Quote
            </td>
            </tr>
            <tr>
            <td>
                Manufacturer
            </td>
             <td>
                <asp:DropDownList ID="OptionManufacturerFilter" runat="server" 
                    DataSourceID="OptionManufacturerDataSource" DataTextField="Name" 
                    DataValueField="Code" AutoPostBack="True" >
                </asp:DropDownList>
            </td>
            </tr>

                            <tr>
            <td colspan="3">
                <asp:GridView ID="NewOptionSelection" 
                              runat="server" 
                              DataSourceID="AvailableOptions" 
                              DataKeyNames="Option_Id"
                              AllowPaging="True" 
                              AllowSorting="True" 
                              AutoGenerateColumns="false">
                <Columns>
                    <asp:BoundField DataField="category_Descr" HeaderText="Category" SortExpression="category_Descr,subcategory_Descr,code" />
                    <asp:BoundField DataField="subcategory_Descr" HeaderText="Sub-Category" SortExpression="subcategory_Descr,code" />
                    <asp:BoundField DataField="Manuf_Name" HeaderText="Manufacturer" SortExpression="Manuf_Name"/>
                </Columns></asp:GridView>
            </td>
            </tr>
            <tr class="HeaderFooter">
            <td colspan="3" class="Center">
                <asp:Button ID="OptionSelectionClose" runat="server" Text="Close" />

            </td>
            </tr>
            </table>
             </ContentTemplate>
            </asp:UpdatePanel>
        </asp:Panel>
       <asp:Button runat="server" ID="HiddenTargetControlForOptionSelectionModalPopup" style="display:none"/>    
        <cc1:ModalPopupExtender ID="OptionSelectionModalPopupExtender" runat="server" 
                                TargetControlID="HiddenTargetControlForOptionSelectionModalPopup"
                                PopupControlID="OptionSelectionPanel" 
                                BackgroundCssClass="modalTextBoxBackground" />

【问题讨论】:

  • 能贴出相关的css和html吗?
  • 我刚刚将代码添加到问题中
  • 我最后一件事是在 上添加 "修复了弹出高度,但我无法将 if 设置为 90%。我还尝试了 或 CSS 中的其他变体无济于事。

标签: asp.net css ajaxcontroltoolkit modalpopupextender


【解决方案1】:

我刚找到这个。

ModalPopupExtender does not show scroll bar

它仍然无法正常工作,但这是因为我使用了母版页,所以我使用 ClientID 解决了这个问题。

(注意:要使内部asp:panel 垂直居中,我发现的唯一方法是使用style="vertical-align:middle" 将其放入表格单元格中。 我还需要使用 JavaScript 设置 OptionSelectionTable 的高度,因为 height="100%" 在某些浏览器中失败。)

<script type="text/javascript">
  function pageLoad() {
      $get('<%= OptionSelectionPanel.ClientID %>').style.height = document.documentElement.clientHeight * 0.9 + "px";
      $get('<%= OptionSelectionTable.ClientID %>').style.height = document.documentElement.clientHeight * 0.9 + "px";
  }
    </script> 

我还必须添加HorizontalAlign="Center"ScrollBars="Auto" 以及Panel ID="OptionSelectionPanel"(modalpopup 的PopupControlID)。

我将CssClass="modalTextBox" 移动到内部asp:panel 并恢复HorizontalAlign="Left"

 <asp:Panel ID="OptionSelectionPanel" runat="server" 
            HorizontalAlign="Center" ScrollBars="auto">
            <asp:UpdatePanel ID="OptionSelectionUpdatePanel" 
                             runat="server" 
                             UpdateMode="Conditional" >
            <Triggers>
                <asp:asyncPostBackTrigger ControlID="TemplateSelection" />
            </Triggers>
            <ContentTemplate>
                <table ID="OptionSelectionTable" 
                       runat="server" 
                       border="0" 
                       cellpadding="0" 
                       cellspacing="0">
                        <tr>
                        <td style="vertical-align:middle">    
                                <asp:Panel ID="OptionSelectionInnerPanel" 
                                           runat="server" 
                                           HorizontalAlign="Left" 
                                           CssClass="modalTextBox">
                                  <table class="EditRow">


                                              ......


                                  </table>
                               </asp:Panel>
                  </td></tr></table> 
             </ContentTemplate>
            </asp:UpdatePanel>
        </asp:Panel>

【讨论】:

    【解决方案2】:

    尝试将整个外部表格元素包装在一个 div 中,并将 div 的高度设置为对话框的高度,然后将新 div 的 css overflow-y 属性设置为滚动。

    [编辑 - jQuery 解决方案]

    看看 jQuery 高度 http://api.jquery.com/height/ 。基本上,您将选择父元素并在运行时更新它的 css 属性,如下所示(未经测试)。请记住,这不是一个理想的解决方案,并且肯定会在浏览器之间有所不同。

    $(document).ready(function() {
       var parentDiv =  $("#yourParentDiv");
       parentDiv.css("height", parentDiv.height());
       parentDiv.css("overflow-y", "scroll");
    });
    

    【讨论】:

    • “将 div 的高度设置为对话框的高度”这个问题,我不想要一个固定的高度,只是显示滚动条之前的最大高度。
    • 您可以使用jQuery或其他工具在客户端运行时计算元素的高度,并相应地设置css。但除此之外,我很确定您目前无法使用 html/css 来尝试使用基于百分比的高度。
    • 如果必须的话,您可以考虑使用 Silverlight 或 Flash 构建一些东西。
    • 好的,也许是 jQuery 或者 javascript。不考虑 Silverlight 或 Flash。需要有关该线索的更多信息...
    • @DavRob60 - 检查我对帖子的最后编辑并尝试一下。
    猜你喜欢
    • 2016-07-02
    • 1970-01-01
    • 2015-10-25
    • 2011-11-21
    • 2016-05-14
    • 1970-01-01
    • 1970-01-01
    • 2011-08-08
    相关资源
    最近更新 更多