UpdatePanel,ModalPopupExtender,并输入按键问题

时间:2011-08-31 22:27:31

标签: c# asp.net webforms updatepanel modalpopupextender

让UpdatePanel包含2个面板,默认按钮设置为侦听输入按键。 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" />

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

1 个答案:

答案 0 :(得分:2)

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

我使用此方法注册脚本:

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。如果没有,则使用完整的回发版本。