Redirection sur clic bouton ok d'un dialog
Bonjour,
J'ai dans ma master un dialog pour afficher si une action s'est correctment déroulée ou non. ça ça marche bien
Mais parfois, j'ai besoin de faire une redirection après le clic du bouton Ok
Voici mon code
Déclaration de la classe de retour de l'action
Code:
1 2 3 4 5 6
|
Public Class msgRetour
Public Property Reussi As Boolean
Public Property Msg As String
Public Property UrlReturn As String
End Class |
Master
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
<%@ Master Language="VB" AutoEventWireup="false" CodeBehind="Master.master.vb" Inherits="Jquery.Master" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="../script/jquery-1.9.0.js" type="text/javascript"></script>
<script src="../script/jquery-ui-1.10.0.custom.min.js" type="text/javascript"></script>
<script src="../script/MsgResult.js" type="text/javascript"></script>
<link href="../CSS/ui-lightness/jquery-ui-1.10.0.custom.min.css" rel="stylesheet"
type="text/css" />
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<style type="text/css">
#checkmark
{
position: absolute;
left: 0px;
top: 10px;
margin-right: 20px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
<div id="MsgBack" title="Download complete">
<div class='subcontent-box' id='Errortitre'>
</div>
</div>
</body>
</html> |
mon fichier MsgResult.js
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| $(function () {
$("#MsgBack").dialog({
autoOpen: false,
modal: true,
buttons: {
Ok: function () {
$(this).dialog("close");
}
}
});
});
function AfficheMsgRetour(Retour) {
if (Retour.Reussi) {
$("#Errortitre").html("<font color=green><I>" + Retour.Msg + "</I></font>");
$('#Errortitre').append("<img id='checkmark' src='Images/clean.png' />");
$("#MsgBack").dialog("open");
}
else {
$("#Errortitre").html("<font color=red><I>" + Retour.Msg + "</I></font>");
$('#Errortitre').append("<img id='checkmark' src='Images/critical.png' />");
$("#MsgBack").dialog("open");
}
if (Retour.UrlReturn) {/*Retourne faux si chaine null,undefine empty,0,false ...*/
$("#MsgBack.Ok").attr("onclick", "window.location = 'Default.aspx';");
}
} |
Ma page héritant de ma master
cote serveur
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
Public Class MDPPMsgComplex
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Session("MaPage") = "MDPPMsgComplex.aspx"
If Not Page.IsPostBack Then Session("MonToken") = New Guid
End Sub
<Services.WebMethod()> _
Public Shared Function AddNewItem(ByVal name As String, ByVal surname As String, ByVal PageEncours As String, ByVal age As Integer) As Master.msgRetour
Dim ret As New Master.msgRetour
Try
Static persons As List(Of Person)
If persons Is Nothing Then persons = New List(Of Person)
Dim Person = New Person()
Person.Name = name
Person.Surname = surname
Person.Age = age
persons.Add(Person)
ret.Reussi = ((persons.Count Mod 2) = 0)
If ret.Reussi Then
ret.Msg = "Trop fort ton Enr enregistré " & HttpContext.Current.Session("MaPage") & vbNewLine & PageEncours
ret.UrlReturn = "Default.aspx"
Else
ret.Msg = "Oups ! Erreur enr non enregistré"
End If
Return ret
Catch ex As Exception
ret.Reussi = False
ret.Msg = ex.Message
Return ret
End Try
End Function
End Class |
cote cllient
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| <%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Master/Master.Master"
CodeBehind="MDPPMsgComplex.aspx.vb" Inherits="Jquery.MDPPMsgComplex" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style type="text/css">
label.error
{
font-weight: normal;
color: red;
text-align: left;
padding-left: 25px;
background: transparent url(/images/Critical.png) no-repeat scroll left;
}
</style>
<script type="text/javascript">
$(function () {
$('.error').hide();
$("#Valider").click(
function () {
$('.error').hide();
var surname = $("#<%= txtSurname.ClientID %>").val();
var age = $("#<%= txtAge.ClientID %>").val();
var name = $("input#name").val();
if (name == "") {
$("label#name_error").show();
$("input#name").focus();
return false;
}
$.ajax({
type: "POST",
url: "MDPPMsgComplex.aspx/AddNewItem",
data: '{"name":"' + name + '", "surname":"' + surname + '", "age":' + age + ',"PageEncours":"' + document.location.href.toString() + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
AfficheMsgRetour(msg.d)
},
error: function () {
alert("Error! Try again...");
}
});
return false;
});
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<table>
<tr>
<td>
Name
</td>
<td>
<input type="text" name="name" id="name" size="30" value="" class="text-input" />
<label class="error" for="name" id="name_error">
This field is required.</label>
</td>
</tr>
<tr>
<td>
Surname
</td>
<td>
<asp:TextBox ID="txtSurname" runat="server" />
</td>
</tr>
<tr>
<td>
Age
</td>
<td>
<asp:TextBox ID="txtAge" runat="server" />
</td>
</tr>
<tr>
<td colspan="2">
<button id="Valider" >
Valider</button>
</td>
</tr>
</table>
</asp:Content> |
Dans mon fichier MsgResult, j'essai d'atteindre le boutton 'Ok'. Mais en fait en cliquant dessus je ne fait que fermer le dialog et je n'ai pas de redirection