ModalPopupExtender 仅在选定索引更改事件上显示,而不在单击 DropDownList 时显示?

发布于 2024-11-18 10:05:21 字数 2714 浏览 2 评论 0原文

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

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

其中一个控件特别是 DDL,我有一个连接到它的模态弹出扩展器。我想仅在选择特定值(而不是索引)时触发 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基于费用类型,我想定位一个特定的值(数据库主键),然后显示模式弹出窗口,以便用户可以输入他们的里程,然后做一些其他事情。

这是我的 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

点网新闻

I said in my last question and will say in this one too, basically my username reflects my experience!

I currently have a page with 2 listviews, one of which has a number of controls in the InsertItem template.

One of these controls in particuilar is a DDL and I have a Modal Popup Extender hooked up to it. I want to trigger the MPE only when a particular value(not index) is selected. Here is where I am up to now!

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();
}

Above are the contents of the DDL SelectedIndexChanged event. This DDL is based on expense types, I want to target a particular value (db primary key) and then display the modal popup so the user can enter their mileage then do some other stuff after.

Here is my 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>

At the moment the mpe shows as soon as the DDL is clicked, but I want that to happen only for the selected value of 1.

Can someone please tell me what I am doing wrong?

TIA

dotnetnewb

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

燃情 2024-11-25 10:05:21

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

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

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

This is happening because you have set up the DDL as target of your modal popup extender - so whenever target index is changed, the dialog is shown. The solution is to have an hidden button and make that a target control for modal popup extender - if your DDL has auto-postback as true then your server side code will check the selected index and popup the dialog.

From user experience perspective, unless you have UpdatePanel on page, this would mean on DDL change, page will refreshed and a dialog will be shown. You can also use modal pop-up javascript API to show/hide on DDL selected index change w/o doing post-back. For example,

$find('mpeMiles').show();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文