ModalPopupExtender 不回发

发布于 2024-09-08 00:48:24 字数 2640 浏览 5 评论 0原文

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

当我单击“邀请”按钮时,它只是隐藏 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>

请帮忙。

谢谢。

I have this page where in i have a ModalPopupExtender. Now the panel that shows up as a ModalPopup has 2 buttons namely "Invite" and "Cancel". My problem is that when i click on either of the buttons postback does not occur and i am unable to run my server side code.

When i click on the "Invite" button it simply hides the ModalPopupExtender control and does nothing!!

    <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>

Please help.

Thank you.

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

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

发布评论

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

评论(2

东走西顾 2024-09-15 00:48:24

取出标记的这一部分:

OkControlID="btnInvite" CancelControlID="btnCancel"

注释后更新:

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

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

所以基本上它创建了一个针对 _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。

Take out this part of your markup:

OkControlID="btnInvite" CancelControlID="btnCancel"

Update after comment:

In the initialization phase, client side, this piece of code gets executed:

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

So basically it creates a handler towards the _onOK function:

_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;
    }
},

as you can see it calls e.preventDefault(); which causes the normal behavior of the OKControl to not go through while this.hide() will close the modal popup itself.

I suggest you read the ModalPopupBehavior.debug.js from the control toolkit if you want to know more.

自此以后,行同陌路 2024-09-15 00:48:24

不要分配 ok 控件,这样事件就可以正常工作。

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

Don't assign the ok control, so event will work fine.

Also it works for cancel control just don't assign them.

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