locked
Ajax Control Toolkit ModalPopup - Dismiss with OK and invoke server method as if Button OnCommand with CommandArgument RRS feed

  • Question

  • User1453632690 posted

    I have a scenario where I want to use the ModalPopup when a form Button is clicked to ask the user to confirm an action. If the user clicks the ModalPopup OK button I want to invoke a code-behind method that uses the same CommandName and CommandArgument that would be used from the Button without the ModalPopup. Any idea how this can be acheived?

    Tuesday, April 8, 2014 10:39 AM

Answers

  • User1208776063 posted

    invoke a code-behind method that uses the same CommandName and CommandArgument that would be used from the Button without the ModalPopup

    Just set the same Onlick attribute, but with different command name/argument for button inside the modal popup panel

    <ajaxtoolkit:modalpopupextender id="MPE" runat="server" targetcontrolid="LinkButton1"
        popupcontrolid="Panel1" backgroundcssclass="modalBackground" dropshadow="true"
        cancelcontrolid="CancelButton" popupdraghandlecontrolid="Panel3">
    </ajaxtoolkit:modalpopupextender>
    <asp:Panel runat="server" ID="Panel1">
        <asp:Button ID="btnOkay" runat="server" Text="OK" CommandArgument="Something" CommandName="Okay_ModalPopup"
            OnCommand="btnOutsideOkay_Command" />
    </asp:Panel>
    protected void btnOutsideOkay_Command(object sender, CommandEventArgs e)
    {
      switch (e.CommandName.ToUpper())
      {
         case "OKAY_MODALPOPUP":
          //do something here
          MPE.Hide();
          break;
      }
    }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 8, 2014 2:23 PM

All replies

  • User-1360095595 posted

    User an asp button and set the commandname/argument as you desire. Then handle the button Command/Click event. Make sure you leave the okcontrolid blank. 

    Tuesday, April 8, 2014 2:13 PM
  • User1208776063 posted

    invoke a code-behind method that uses the same CommandName and CommandArgument that would be used from the Button without the ModalPopup

    Just set the same Onlick attribute, but with different command name/argument for button inside the modal popup panel

    <ajaxtoolkit:modalpopupextender id="MPE" runat="server" targetcontrolid="LinkButton1"
        popupcontrolid="Panel1" backgroundcssclass="modalBackground" dropshadow="true"
        cancelcontrolid="CancelButton" popupdraghandlecontrolid="Panel3">
    </ajaxtoolkit:modalpopupextender>
    <asp:Panel runat="server" ID="Panel1">
        <asp:Button ID="btnOkay" runat="server" Text="OK" CommandArgument="Something" CommandName="Okay_ModalPopup"
            OnCommand="btnOutsideOkay_Command" />
    </asp:Panel>
    protected void btnOutsideOkay_Command(object sender, CommandEventArgs e)
    {
      switch (e.CommandName.ToUpper())
      {
         case "OKAY_MODALPOPUP":
          //do something here
          MPE.Hide();
          break;
      }
    }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 8, 2014 2:23 PM