2010-07-06 109 views
0

我有这个网页,我有一个ModalPopupExtender。现在显示为ModalPopup的面板有2个按钮,即“邀请”和“取消”。我的问题是,当我点击任一按钮回发不会发生,我无法运行我的服务器端代码。ModalPopupExtender不回发

当我点击“邀请”按钮时,它只是隐藏ModalPopupExtender控件并且什么也不做!

<asp:ModalPopupExtender ID="mpeInviteFriend" runat="server" 
    TargetControlID="lbInvite" PopupControlID="pnlInviteFriend" 
    OkControlID="btnInvite" CancelControlID="btnCancel" 
    BackgroundCssClass="diabledBackground" Y="100"></asp:ModalPopupExtender> 

<asp:Panel ID="pnlInviteFriend" runat="server"> 
    <div class="popUpBoxBackground" style="height:230px; width: 400px"> 
    <div class="popUpBox"> 
    <div class="popUpHeader"> 
    <b>Invite a Friend</b> 
    </div> 
    <div class="popUpBody" style="height:210px"> 
    <div style="padding: 10px"> 
     <table cellpadding="0" cellspacing="0" border="0" width="100%"> 
     <tr> 
     <td>You have chosen to invite your friend to join this community.</td> 
     </tr> 
     <tr> 
     <td style="padding: 8px 0px 0px 0px">Email address of your friend:</td> 
     </tr> 
     <tr> 
     <td style="padding: 4px 0px 5px 0px" align="right"> 
     <asp:TextBox ID="TextBox1" runat="server" 
      TextMode="MultiLine" CssClass="inputTextbox" 
      Width="99%" Height="28px"></asp:TextBox> 
     <span class="smallInfoText" style="color: #000">In case you want to invite more than 1 friend, separate their mail id with a ;</span> 
     </td> 
     </tr> 
     <tr> 
     <td style="padding: 4px 0px 0px 0px">Would you like to add a personal note?</td> 
     </tr> 
     <tr> 
     <td style="padding: 4px 0px 5px 0px" align="right"> 
     <asp:TextBox ID="txtInvitationText" runat="server" 
      TextMode="MultiLine" CssClass="inputTextbox" 
      Width="99%"></asp:TextBox> 
     <span class="smallInfoText" style="color: #000">If not then leave it blank and we will take care of the note :)</span> 
     </td> 
     </tr> 
     <tr> 
     <td align="right"> 
     <asp:Button ID="btnInvite" runat="server" OnClick="btnInvite_Click" Text="Invite" style="margin-right: 10px" Width="60px" /> 
     <asp:Button ID="btnCancel" runat="server" OnClick="btnCancel_Click" Text="Cancel" Width="60px" /> 
     </td> 
     </tr> 
     </table> 
    </div> 
    </div> 
    </div> 
    </div> 
</asp:Panel> 

请帮忙。

谢谢。

回答

0

拿出你的标记,这部分:

在初始化阶段,客户端,这段代码被执行:

if (this._OkControlID) { 
     this._okHandler = Function.createDelegate(this, this._onOk); 
     $addHandler($get(this._OkControlID), 'click', this._okHandler); 
    } 

所以评论后

OkControlID="btnInvite" CancelControlID="btnCancel" 

更新基本上它创建了一个对_onOK函数的处理程序:

_onOk: function(e) { 
    /// <summary> 
    /// Handler for the modal dialog's OK button click 
    /// </summary> 
    /// <param name="e" type="Sys.UI.DomEvent"> 
    /// Event info 
    /// </param> 

    var element = $get(this._OkControlID); 
    if (element && !element.disabled) { 
     if (this.hide() && this._OnOkScript) { 
      window.setTimeout(this._OnOkScript, 0); 
     } 
     e.preventDefault(); 
     return false; 
    } 
}, 

你可以看到它调用e.preventDefault();这会导致OKControl的正常行为无法通过,而this.hide()将关闭模式弹出窗口。

如果您想了解更多信息,建议您阅读控制工具包中的ModalPopupBehavior.debug.js。

+0

谢谢哥们,那个解决方法就是我想要的......但是你能否详细解释我的现象...... 当我删除那段代码时究竟发生了什么? – Shrewdroid 2010-07-06 11:20:08

+0

我用额外的代码更新了我的原始回复。 – XIII 2010-07-06 12:20:51

+0

感谢哥们多谢,真的很感谢! – Shrewdroid 2010-07-07 06:03:12

0

不要分配OK控件,所以事件会正常工作。

它也适用于取消控制只是不分配它们。

相关问题