Popup confirmation before ASP.NET Form Submit

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Straumann

    Popup confirmation before ASP.NET Form Submit

    Hi all:

    I have an ASP.NET form that submits info to the server, but the customer
    wants a confirmation window to open when the user clicks "Submit", and then
    the user would have to click "OK" on the popup window to have the main form
    submit. I found some samples of using JavaScript to create a popup window,
    but then the OnClick event for the form button runs the JavaScript as
    opposed to the server side code.

    Can anyone suggest how I can accomplish this?

    Thanks.

    John.



  • Mark Rae [MVP]

    #2
    Re: Popup confirmation before ASP.NET Form Submit

    "John Straumann" <jstraumann@hot mail.comwrote in message
    news:67BF7796-90C6-40A1-9E23-92D3DDDFD1A0@mi crosoft.com...
    Can anyone suggest how I can accomplish this?
    <asp:Button ID="cmdSubmit" runat="server" Text = "Submit"
    OnClick="cmdSub mit_Click" OnClientClick=" return confirm('Are you sure?');"
    />


    --
    Mark Rae
    ASP.NET MVP


    Comment

    • sloan

      #3
      Re: Popup confirmation before ASP.NET Form Submit


      This code is my "Cancel Page" confirmation.

      If I pick "Yes" (to Cancel), my code behind (button) code runs, and
      redirects me.
      If I pick "No", I stay on the page.


      CancelButtonCon firmInsertion (this.Page , button1 ); // is all I need on the
      page.




      public enum AppendOrder
      {
      BEFORE_CURRENT_ ITEMS = 1,
      AFTER_CURRENT_I TEMS = 2
      }
      public class ObjectUtilityLi b
      {

      private ObjectUtilityLi b()
      {
      }




      /// <summary>
      /// Attaches a 'Are you sure you want to cancel?' javascript confirm
      message to a webcontrol.
      /// </summary>
      /// <param name="TargetPag e">The target page.</param>
      /// <param name="c">The control to attach the javascript cancel
      confirm.</param>
      public static void CancelButtonCon firmInsertion(P age TargetPage,
      System.Web.UI.W ebControls.WebC ontrol c)
      {
      string jsFunction = "return confirm('Are you sure you would like
      to cancel?');";
      //jsFunction = "return true;";
      AppendAttribute (c, "onClick", jsFunction,
      Web.Utilities.A ppendOrder.AFTE R_CURRENT_ITEMS );

      }



      /// <summary>
      /// Appends the attribute.
      /// </summary>
      /// <param name="c">The webcontrol to which the Javascript will be
      appended.</param>
      /// <param name="eventName ">Name of the javascript event for the
      control.</param>
      /// <param name="newScript ">The new script text.</param>
      /// <param name="ao">The AppendOrder.</param>
      public static void
      AppendAttribute (System.Web.UI. WebControls.Web Control c, string eventName,
      string newScript, AppendOrder ao)
      {
      string currentAttrib;
      currentAttrib = c.Attributes[eventName];
      if (!(currentAttri b == null))
      {
      if (ao == AppendOrder.BEF ORE_CURRENT_ITE MS)
      {
      c.Attributes.Ad d(eventName, newScript + currentAttrib);
      }
      else
      {
      c.Attributes.Ad d(eventName, currentAttrib + newScript);
      }
      }
      else
      {
      c.Attributes.Ad d(eventName, newScript);
      }
      }
      }






      "John Straumann" <jstraumann@hot mail.comwrote in message
      news:67BF7796-90C6-40A1-9E23-92D3DDDFD1A0@mi crosoft.com...
      Hi all:
      >
      I have an ASP.NET form that submits info to the server, but the customer
      wants a confirmation window to open when the user clicks "Submit", and
      then the user would have to click "OK" on the popup window to have the
      main form submit. I found some samples of using JavaScript to create a
      popup window, but then the OnClick event for the form button runs the
      JavaScript as opposed to the server side code.
      >
      Can anyone suggest how I can accomplish this?
      >
      Thanks.
      >
      John.
      >
      >
      >

      Comment

      • John Straumann

        #4
        Re: Popup confirmation before ASP.NET Form Submit

        Hi Mark:

        Thanks for the note. My apologies as I neglected to mention that the popup
        window needs to display a "terms and conditions" document (so a fairly large
        amount of text) and then react to the click of the "OK" button. I tried to
        put a large string in the code below but it did not work. I use mostly code
        behind files, but would it be possible to declare a variable in ASP.NET
        script that holds the text, and then use the variable name in the return
        confirm?

        John.

        "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
        news:ufQYI95OJH A.4328@TK2MSFTN GP02.phx.gbl...
        "John Straumann" <jstraumann@hot mail.comwrote in message
        news:67BF7796-90C6-40A1-9E23-92D3DDDFD1A0@mi crosoft.com...
        >
        >Can anyone suggest how I can accomplish this?
        >
        <asp:Button ID="cmdSubmit" runat="server" Text = "Submit"
        OnClick="cmdSub mit_Click" OnClientClick=" return confirm('Are you sure?');"
        />
        >
        >
        --
        Mark Rae
        ASP.NET MVP
        http://www.markrae.net

        Comment

        • sloan

          #5
          Re: Popup confirmation before ASP.NET Form Submit


          You can try lots of returns in the long string message.

          I would look at Telerik, as they have a form of a "Modal Window" for
          Asp.Net.





          "John Straumann" <jstraumann@hot mail.comwrote in message
          news:66B463E1-61FD-4DDC-9637-88D68BB6EA65@mi crosoft.com...
          Hi Mark:
          >
          Thanks for the note. My apologies as I neglected to mention that the popup
          window needs to display a "terms and conditions" document (so a fairly
          large amount of text) and then react to the click of the "OK" button. I
          tried to put a large string in the code below but it did not work. I use
          mostly code behind files, but would it be possible to declare a variable
          in ASP.NET script that holds the text, and then use the variable name in
          the return confirm?
          >
          John.
          >
          "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
          news:ufQYI95OJH A.4328@TK2MSFTN GP02.phx.gbl...
          >"John Straumann" <jstraumann@hot mail.comwrote in message
          >news:67BF779 6-90C6-40A1-9E23-92D3DDDFD1A0@mi crosoft.com...
          >>
          >>Can anyone suggest how I can accomplish this?
          >>
          ><asp:Button ID="cmdSubmit" runat="server" Text = "Submit"
          >OnClick="cmdSu bmit_Click" OnClientClick=" return confirm('Are you
          >sure?');" />
          >>
          >>
          >--
          >Mark Rae
          >ASP.NET MVP
          >http://www.markrae.net
          >

          Comment

          Working...