【问题标题】:ModalPopupExtender only show on Selected index changed event, not on clicking DropDownList?ModalPopupExtender 仅在 Selected index changed 事件上显示,而不是在单击 DropDownList 时显示?
【发布时间】:2011-07-01 09:40:48
【问题描述】:

我在上一个问题中说过,也会在这个问题中说,基本上我的用户名反映了我的经验!

我目前有一个包含 2 个列表视图的页面,其中一个在 InsertItem 模板中有许多控件。

其中一个控件特别是 DDL,我有一个 Modal Popup Extender 连接到它。我只想在选择特定值(不是索引)时触发 MPE。这就是我现在的位置!

DropDownList ExpenseTypeDDL = 
    (DropDownList) Expenses.InsertItem.FindControl("ExpenseTypeDDL");
int ExpenseType = (Int32.Parse(ExpenseTypeDDL.SelectedValue.ToString()));

if (ExpenseType == 1)
{
    AjaxControlToolkit.ModalPopupExtender mpeMiles = 
        (AjaxControlToolkit.ModalPopupExtender)Expenses.InsertItem.
        FindControl("mpeMiles");
    mpeMiles.Show();
}

以上是 DDL SelectedIndexChanged 事件的内容。这个 DDL 是基于费用类型的,我想定位一个特定的值(db 主键),然后显示模式弹出窗口,这样用户就可以输入他们的里程数,然后再做一些其他的事情。

这是我的mpe

<cc1:ModalPopupExtender ID ="mpeMiles" TargetControlID ="ExpenseTypeDDL" 
    runat="server" DropShadow="true" PopupControlID="pnlMiles" 
    BackgroundCssClass="modalBackground" />
<asp:Panel CssClass="modalPopup" ID="pnlMiles" runat="server" 
    Height="170px">
    <div style="padding: 5px; text-align:center">
        <asp:Label ID="lblStart" runat="server">Start location.</asp:Label>
        <asp:TextBox ID="txtLocationStart" runat="server" />
        <asp:RequiredFieldValidator ID="reqLocation" runat="server" 
            ErrorMessage="You must enter a start location" 
            ControlToValidate="txtLocationStart" Display="Dynamic" Text="*" >
        </asp:RequiredFieldValidator>
        <asp:Label ID="lblDestination" runat="server">Destination.</asp:Label>
        <asp:TextBox ID="txtDestination" runat="server" />
        <asp:RequiredFieldValidator ID="reqDestination" runat="server" 
            ErrorMessage="You must enter a destination" 
            ControlToValidate="txtDestination" Display="Dynamic" Text="*" >
        </asp:RequiredFieldValidator>
        <asp:Label ID="lblMiles" runat="server">Please enter your Mileage</asp:Label>
        <asp:RequiredFieldValidator ID="reqMileage" runat="server" 
            ErrorMessage="You must enter your mileage" ControlToValidate="txtMiles" 
            Display="Dynamic" Text="*" ></asp:RequiredFieldValidator>
        <asp:TextBox ID="txtMiles" runat="server" />
        <br />
        <br />
        <asp:Button ID="btnMiles_OK" runat="server" Text="Save" 
            CausesValidation="false" />
        <asp:Button ID="btnMiles_Cancel" runat="server" Text="Cancel" 
            CausesValidation="false"/>
    </div>
</asp:Panel>

目前,只要单击 DDL,mpe 就会显示,但我希望仅对所选值 1 发生这种情况。

谁能告诉我我做错了什么?

TIA

dotnetnewb

【问题讨论】:

  • 我想用javascript调用显示弹出扩展器会更好。
  • 这是越来越多的人告诉我的,我被指示暂时不要碰JS。

标签: asp.net drop-down-menu modalpopupextender


【解决方案1】:

发生这种情况是因为您已将 DDL 设置为模态弹出扩展器的目标 - 因此,只要更改目标索引,就会显示对话框。解决方案是有一个隐藏按钮并将其作为模态弹出扩展器的目标控件 - 如果您的 DDL 将自动回发设置为 true,那么您的服务器端代码将检查所选索引并弹出对话框。

从用户体验的角度来看,除非您在页面上有 UpdatePanel,否则这意味着在 DDL 更改时,页面将刷新并显示一个对话框。您还可以使用模态弹出式 JavaScript API 来显示/隐藏 DDL 选择的索引更改而不进行回发。例如,

$find('mpeMiles').show();

【讨论】:

  • 谢谢 VinayC,这是最有帮助的。虽然我正在做的是一个真正的项目,但它也是一个培训练习,我被指示避免使用 JS(现在)。我有 mpeMiles.Hide();在listview的bind方法中,但仍然在页面上显示面板静态
猜你喜欢
  • 2017-11-21
  • 1970-01-01
  • 2011-06-14
  • 1970-01-01
  • 2017-06-24
  • 2015-04-22
  • 1970-01-01
  • 2018-07-25
  • 2019-10-04
相关资源
最近更新 更多