UpdatePanel、ModalPopupExtender 和 Enter 按键问题

发布于 2024-12-02 15:43:27 字数 3717 浏览 1 评论 0原文

有一个包含 2 个面板的 UpdatePanel,其中默认按钮设置为监听输入按键。 UpdatePanel 是 ModalPopupExtender 的 PopupControl。

在整个页面回发的模态弹出窗口中按 Enter 时遇到问题。有什么想法吗?以下是一些代码片段(我已删除无关的字段...):

<div runat="server" id="divShippingEstimatorPopup" class="shippingEstimatorModalPopup">
<asp:UpdatePanel ID="upPopup" runat="server">
    <ContentTemplate>
        <asp:Panel runat="server" ID="pnlShippingEstimator" DefaultButton="lnkbtnGetEstimates">
            <div class="title content_title">Shipping Estimator</div>
            <asp:Label runat="server" ID="lblMessage" />
            <table cellpadding="0" cellpadding="0" class="shipping">
                <!-- Removed to shorten code snippet -->
                <tr>
                    <td colspan="2">
                        <div class="buttonHolder">                            
                            <Monarch:LinkButtonDefault runat="server" ID="lnkbtnGetEstimates" CssClass="button_action button_margin_right" CausesValidation="false">Get Estimates</Monarch:LinkButtonDefault>
                            <asp:LinkButton runat="server" ID="lnkbtnCancel" CssClass="button_secondary button_secondary_fixed" CausesValidation="false">Cancel</asp:LinkButton>
                            <div class="clear"></div>
                        </div>
                        <div class="clear"></div>
                    </td>
                </tr>
            </table>
        </asp:Panel>
        <asp:Panel runat="server" ID="pnlShippingOptions" DefaultButton="lnkbtnSetEstimate">
            <div class="shippingOptionsHolder" runat="server" id="divShippingOptionsHolder">
                <!-- Removed to shorten code snippet -->
                <div class="buttonHolder">
                    <Monarch:LinkButtonDefault runat="server" ID="lnkbtnSetEstimate" CssClass="button_action">Set Estimate</Monarch:LinkButtonDefault>
                    <div class="clear"></div>
                </div>
                <div class="clear"></div>
            </div>
        </asp:Panel>
    </ContentTemplate>
</asp:UpdatePanel>

请记住 LinkBut​​tonDefault 就是这样:

public class LinkButtonDefault : LinkButton
{
    private const string AddClickScript = "SparkPlugs.FixLinkButton('{0}');";

    protected override void OnLoad(EventArgs e)
    {
        string script = String.Format(AddClickScript, ClientID);
        Page.ClientScript.RegisterStartupScript(GetType(), "click_" + ClientID,
            script, true);
        base.OnLoad(e);
    }
}

最后,这是控件的其余部分:

<asp:UpdatePanel runat="server" ID="upGetEstimate">
    <ContentTemplate>
        <asp:LinkButton runat="server" ID="lnkbtnGetEstimate" CausesValidation="false">Get Estimate</asp:LinkButton>
    </ContentTemplate>
</asp:UpdatePanel>

<ajaxToolKit:ModalPopupExtender ID="shippingEstimatorPopupExtender" runat="server" TargetControlID="lnkbtnFake" PopupControlID="divShippingEstimatorPopup" BackgroundCssClass="monarchModalBackground"></ajaxToolKit:ModalPopupExtender>
<asp:LinkButton runat="server" ID="lnkbtnFake" style="display:none;"/>

<Monarch:PopupProgress ID="popupProgressGetEstimate" runat="server" AssociatedUpdatePanelId="upGetEstimate" />
<Monarch:PopupProgress ID="popupProgressGetEstimates" runat="server" AssociatedUpdatePanelId="upPopup" />

基本上,用户单击“获取估计”,加载表单时会出现一个进度条,表单显示在模式弹出窗口中。我猜这很简单,但我不能仅仅获得正确的组合来使其正常工作。

Have an UpdatePanel that contains 2 panels with default buttons set to listen to enter key presses. That UpdatePanel is the PopupControl for a ModalPopupExtender.

Running into an issue when pressing enter in the modal popup in which the entire page posts back. Any ideas? Here are some code snippets (I've removed the extraneous fields...):

<div runat="server" id="divShippingEstimatorPopup" class="shippingEstimatorModalPopup">
<asp:UpdatePanel ID="upPopup" runat="server">
    <ContentTemplate>
        <asp:Panel runat="server" ID="pnlShippingEstimator" DefaultButton="lnkbtnGetEstimates">
            <div class="title content_title">Shipping Estimator</div>
            <asp:Label runat="server" ID="lblMessage" />
            <table cellpadding="0" cellpadding="0" class="shipping">
                <!-- Removed to shorten code snippet -->
                <tr>
                    <td colspan="2">
                        <div class="buttonHolder">                            
                            <Monarch:LinkButtonDefault runat="server" ID="lnkbtnGetEstimates" CssClass="button_action button_margin_right" CausesValidation="false">Get Estimates</Monarch:LinkButtonDefault>
                            <asp:LinkButton runat="server" ID="lnkbtnCancel" CssClass="button_secondary button_secondary_fixed" CausesValidation="false">Cancel</asp:LinkButton>
                            <div class="clear"></div>
                        </div>
                        <div class="clear"></div>
                    </td>
                </tr>
            </table>
        </asp:Panel>
        <asp:Panel runat="server" ID="pnlShippingOptions" DefaultButton="lnkbtnSetEstimate">
            <div class="shippingOptionsHolder" runat="server" id="divShippingOptionsHolder">
                <!-- Removed to shorten code snippet -->
                <div class="buttonHolder">
                    <Monarch:LinkButtonDefault runat="server" ID="lnkbtnSetEstimate" CssClass="button_action">Set Estimate</Monarch:LinkButtonDefault>
                    <div class="clear"></div>
                </div>
                <div class="clear"></div>
            </div>
        </asp:Panel>
    </ContentTemplate>
</asp:UpdatePanel>

Keep in mind the LinkButtonDefault is just this:

public class LinkButtonDefault : LinkButton
{
    private const string AddClickScript = "SparkPlugs.FixLinkButton('{0}');";

    protected override void OnLoad(EventArgs e)
    {
        string script = String.Format(AddClickScript, ClientID);
        Page.ClientScript.RegisterStartupScript(GetType(), "click_" + ClientID,
            script, true);
        base.OnLoad(e);
    }
}

Finally, here is the rest of the control:

<asp:UpdatePanel runat="server" ID="upGetEstimate">
    <ContentTemplate>
        <asp:LinkButton runat="server" ID="lnkbtnGetEstimate" CausesValidation="false">Get Estimate</asp:LinkButton>
    </ContentTemplate>
</asp:UpdatePanel>

<ajaxToolKit:ModalPopupExtender ID="shippingEstimatorPopupExtender" runat="server" TargetControlID="lnkbtnFake" PopupControlID="divShippingEstimatorPopup" BackgroundCssClass="monarchModalBackground"></ajaxToolKit:ModalPopupExtender>
<asp:LinkButton runat="server" ID="lnkbtnFake" style="display:none;"/>

<Monarch:PopupProgress ID="popupProgressGetEstimate" runat="server" AssociatedUpdatePanelId="upGetEstimate" />
<Monarch:PopupProgress ID="popupProgressGetEstimates" runat="server" AssociatedUpdatePanelId="upPopup" />

Basically, the user clicks Get Estimate, a progress bar appears while it loads the form, the form shows in a modal popup. I'm guessing this is something simple, but I can't just get the right combination to get this working properly.

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

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

发布评论

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

评论(1

落在眉间の轻吻 2024-12-09 15:43:27

首先尝试一下如果您使用脚本管理器在后面的代码中注册脚本会发生什么。

我使用此方法来注册脚本:

public static void RegisterStartupScript(Control c, string script)
{
    if ((ToolkitScriptManager.GetCurrent(c.Page) as ToolkitScriptManager).IsInAsyncPostBack)
        ToolkitScriptManager.RegisterStartupScript(c, c.GetType(), "Script_" + c.ClientID.ToString(), script, true);
    else
        c.Page.ClientScript.RegisterStartupScript(c.GetType(), c.ClientID, script, true);
}

这会检查您的页面中是否有 ScriptManager。如果没有,它将使用完整的回发版本。

First of all try what happens if you use your scriptmanager to register script in the code behind.

I use this method for registering scripts:

public static void RegisterStartupScript(Control c, string script)
{
    if ((ToolkitScriptManager.GetCurrent(c.Page) as ToolkitScriptManager).IsInAsyncPostBack)
        ToolkitScriptManager.RegisterStartupScript(c, c.GetType(), "Script_" + c.ClientID.ToString(), script, true);
    else
        c.Page.ClientScript.RegisterStartupScript(c.GetType(), c.ClientID, script, true);
}

This checks if you have ScriptManager in your page. If it doesn't, it uses the full postback version.

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