Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3343458
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:57:25+00:00 2026-05-18T00:57:25+00:00

I’m new to jQuery and I want to do this simple thing in a

  • 0

I’m new to jQuery and I want to do this simple thing in a ASP.Net application:

I have a button in the the form and which when clicked I want to execute some server side code. BUT I want the user confirmation first, given through a jQuery modal dialog.

Which of the following approaches is correct:

1) Put the ASP.Net button (server control who’s OnClick is linked to the server side event) in the form and use jQuery to open the dialog when clicked:

<script ...>
    $(document).ready(function ()
    {
        $("#ConfirmDialog").dialog(
        {
            autoOpen: false,
            modal: true,
            buttons: {
                'Yes': function () { return true; },
                'No': function () { return false; }
            }
        });

        $("#<%= SubmitButton.ClientID %>").click(function (event) {
            event.preventDefault();
            $("#ConfirmDialog").dialog('open');
        });
    });
</script>
...
<div id="ConfirmDialog"></div>
...
<asp:Button ID="SubmitButton" runat="server" 
        Text="Submit" OnClick="Submit_Click" />

2) Put the ASP.Net Button (server control) in the div used as the confirmation dialog and put a HTML button (non server control) in the form for the user to click.

<script ...>
    $(document).ready(function ()
    {
        $("#ConfirmDialog").dialog(
        {
            autoOpen: false,
            modal: true
        });

        $("#SubmitButton").click(function (event) {
            $("#ConfirmDialog").dialog('open');
        });
    });
</script>
...
<div id="ConfirmDialog">
    <asp:Button ID="SubmitButton" runat="server" 
            Text="Yes" OnClick="Submit_Click" />        
    ...
</div>
...
<input id="SubmitButton" type="button" value="Submit" />

I’m going with the first approach but can’t make it work, is it ok to do event.PreventDefault() and then just return true; in the Yes button?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:57:26+00:00Added an answer on May 18, 2026 at 12:57 am

    The 2nd approach is more correct. If you think about it, you want to use server-side controls when you want some interaction with the server. In this case, you don’t want to interact with the server, but put up a client-side modal dialog, which requires zero interaction with the server to accomplish.

    I’d use the following (untested):

    <script ...>
        $(document).ready(function ()
        {
            $("#ConfirmDialog").dialog(
            {
                autoOpen: false,
                modal: true
            });
    
            $("#SubmitButtonClient").click(function (event) {
                $("#ConfirmDialog").dialog('open');
            });
        });
    </script>
    ...
    <div id="ConfirmDialog">
        <asp:Button ID="SubmitButton" runat="server" 
                Text="Yes" OnClick="Submit_Click" />        
        ...
    </div>
    ...
    <input id="SubmitButtonClient" type="button" value="Submit" />
    

    All I changed was the id of the client-side submit button. In this approach, you don’t need to do event.PreventDefault(). Note that I haven’t tested the above code.

    However, since jQuery is very AJAX-oriented, you generally don’t want to do a server postback to accomplish your “button press”, but use an AJAX post. This will prevent the entire page from reloading, and you can adjust your page as needed. See the ajax() method in jQuery for some examples. You’ll notice that in ASP.NET MVC you don’t see nearly as many server-side controls, but a richer integration with jQuery. This is the general direction Microsoft is headed – fewer server controls and more AJAX-level integration.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.