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 (eg: "Please enter a valid email address and try again").
Kindly explain exactly what code needs to go in which files. ie controller, view, model, scripts, css, etc...
Thanks
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.
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>
看看这些JQuery插件这里肯定有帮助
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.