0

Can somebody please explain how I can create a dialog box that will appear when the user clicks a button on a webpage. I am using the MVC3 framework coding in c# and asp.net.

Basically, when the user clicks 'Send' - the dialog box will display "message has been sent" and they can close it. In the instance that there were validation errors the dialog box should display it (e.g: "Please enter a valid email address and try again").

Kindly explain exactly what code needs to go in which files. i.e. controller, view, model, scripts, css, etc...

Thanks

3 Answers 3

1

You have to use Javascript. From C# you should have an OnClientClick event. Put there you scriptlet like this:

OnClientClick="alert('Hello World!');"

Return true or false base on if you want the server-side click to happen or not:

OnClientClick="return confirm('Are you sure?');"

If this code is not exactly perfect it will still lead you to the correct solution, because basically there aren't any other options really.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the reply. Using the MVC framework how can this be applied?
1

you can use jQuery UI modal:

  <script>
  $(function() {
    $( "#dialog-message" ).dialog({
      modal: true,
      buttons: {
        Ok: function() {
          $( this ).dialog( "close" );
        }
      }
    });
  });
  </script>

<div id="dialog-message" title="Download complete">
  <p id="messageText">
  </p>
</div>

And after click on button you can send ajax request and on success set message in this dialog and show it.

EDIT:

<input type = "submit" id="doSomethingButton">

<script>
    $(function(){
        $('#doSomethingButton').click(function(){
            $.ajax({
                url:"url-to-send-data",
                data:"", // optional
                type:"http-method-type", //GET, POST, DELETE, PUT ....
                success:function(data){
                    $('#messageText').text(data);
                    $('#dialog-message').dialog('open');
                }
            });
        });
    });
</script>

2 Comments

the button they click is an <input type = "submit"> tag so that it can return to the controller which will send an email. Then the dialog box needs to appear. so somehow need to integrate the <button onclick="blah"> together with it?¿
Thanks, but dont they need to be in <script> tags. Also its not working :/
0

See these JQuery plugin's Here this is of sure help

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.