PDA

View Full Version : [CLOSED] confirm codebehind?



hdsoso
May 27, 2014, 9:50 AM
var jfun = new JFunction {Handler = "sss"};
if (selectedrows.Count > 0)
{
X.Msg.Confirm("警告", "真的要删除吗?", jfun);
}
foreach (var submittedNode in selectedrows)
{
var realid = submittedNode.Attributes["realid"].ToString();
X.Msg.Alert("realid", realid).Show();
}

Handler must be a javascript function ? can do it codebehind?

hdsoso
May 27, 2014, 10:37 AM
I wrote a test case blow, i want to show a confirm messagebox before execute directevent method.but BeforeConfirm does not work well


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm50.aspx.cs" Inherits="web.qizweb.com.test.WebForm50" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{

}

protected void DeleteArea(object sender, DirectEventArgs e)
{
X.Msg.Alert("alert", "see this before confirm ?").Show();
}

</script>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server" SourceFormatting="True"></ext:ResourceManager>
<ext:TreePanel runat="server" ID="tp_prov">
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" Text="删除" Icon="Delete">
<DirectEvents>
<Click OnEvent="DeleteArea">
<Confirmation Message="确实要删除吗?" BeforeConfirm="
var tree = App.tp_prov;
var selection = App.tp_prov.getSelectionModel().getSelection();
return App.tp_prov.getSelectionModel().getSelection().len gth>0?true:false;
">
</Confirmation>
</Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Root>
<ext:Node Text="s1">
<Children>
<ext:Node Text="s2" Leaf="True"></ext:Node>
</Children>
</ext:Node>
</Root>
<SelectionModel>
<ext:TreeSelectionModel runat="server" Mode="Multi" ID="tsm_area"></ext:TreeSelectionModel>
</SelectionModel>
</ext:TreePanel>
</form>
</body>
</html>

Daniil
May 27, 2014, 12:27 PM
Hi @hdsoso,

Please set up ConfirmRequest="true" for <Confirmation>.

hdsoso
May 27, 2014, 1:27 PM
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm50.aspx.cs" Inherits="web.qizweb.com.test.WebForm50" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{

}

protected void DeleteArea(object sender, DirectEventArgs e)
{
X.Msg.Alert("alert", "see this before confirm ?").Show();
}

</script>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server" SourceFormatting="True"></ext:ResourceManager>
<ext:TreePanel runat="server" ID="tp_prov">
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" Text="删除" Icon="Delete">
<DirectEvents>
<Click OnEvent="DeleteArea">
<Confirmation Message="确实要删除吗?" ConfirmRequest="True" BeforeConfirm="
var tree = App.tp_prov;
var selection = App.tp_prov.getSelectionModel().getSelection();
return selection.length>0;
">
</Confirmation>
</Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Root>
<ext:Node Text="s1">
<Children>
<ext:Node Text="s2" Leaf="True"></ext:Node>
</Children>
</ext:Node>
</Root>
<SelectionModel>
<ext:TreeSelectionModel runat="server" Mode="Multi" ID="tsm_area"></ext:TreeSelectionModel>
</SelectionModel>
</ext:TreePanel>
</form>
</body>
</html>


why return false , the DeleteArea execute ?

Daniil
May 27, 2014, 6:07 PM
Returning false from a DirectEvent's BeforeConfirm means cancelling of a confirmation dialogue, not a DirectEvent itself.

If you need to cancel a DirectEvent itself, please return false from a DirectEvent's Before handler.

hdsoso
May 28, 2014, 2:33 AM
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm50.aspx.cs" Inherits="web.qizweb.com.test.WebForm50" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{

}

protected void DeleteArea(object sender, DirectEventArgs e)
{
X.Msg.Alert("alert", "see this before confirm ?").Show();
}

</script>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server" SourceFormatting="True"></ext:ResourceManager>
<ext:TreePanel runat="server" ID="tp_prov">
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" Text="删除" Icon="Delete">
<DirectEvents>
<Click OnEvent="DeleteArea" Before="
var tree = App.tp_prov;
var selection = tree.getSelectionModel().getSelection();
if(selection.length==0){
Ext.Msg.alert('提示', '请选择地区');
return false;
}else{
Ext.MessageBox.confirm('询问', '您确定要删除吗?', function (opt) {
if (opt == 'yes') {
return true;
}else{
return false;
}
});
}
">

</Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Root>
<ext:Node Text="s1">
<Children>
<ext:Node Text="s2" Leaf="True"></ext:Node>
</Children>
</ext:Node>
</Root>
<SelectionModel>
<ext:TreeSelectionModel runat="server" Mode="Multi" ID="tsm_area"></ext:TreeSelectionModel>
</SelectionModel>
</ext:TreePanel>
</form>
</body>
</html>



the directevent handler dose not wait result of user click "yes" or "no"
may be must use directmethod?

Daniil
May 28, 2014, 5:37 AM
Ext.Msg.confirm() is asynchronous thing. Its callback function is executed after. In this case your Before handler doesn't return anything,

As far as I can understand you should use both the handlers - Before and BeforeConfirm.

hdsoso
May 28, 2014, 5:40 AM
i use


<ext:Button runat="server" Text="删除" Icon="Delete">
<Listeners>
<Click Handler="
var tree = App.tp_prov;
var selection = tree.getSelectionModel().getSelection();
if(selection.length==0){
Ext.Msg.alert('提示', '请选择地区');
}else{
Ext.MessageBox.confirm('询问', '您确定要删除吗?', function (opt) {
if (opt == 'yes') {
App.direct.DeleteArea();
}
});
}
">
</Click>
</Listeners>
</ext:Button>


but, i want use your mehod,can you give me an example?

Daniil
May 28, 2014, 6:07 AM
Probably, this should work as you need.

<ext:Button runat="server" Text="DirectEvent">
<DirectEvents>
<Click
OnEvent="TestDirectEventHandler"
Before="if (/* no selection */) { return false; }">
<Confirmation
ConfirmRequest="true"
BeforeConfirm="if ( /* no selection */ ) { return false; }"
/>
</Click>
</DirectEvents>
</ext:Button>

hdsoso
May 28, 2014, 11:30 AM
thanks, Daniil
work well below


<ext:Button runat="server" Text="删除" Icon="Delete">
<DirectEvents>
<Click OnEvent="DeleteArea" Before="
var tree = App.tp_prov;
var selection = tree.getSelectionModel().getSelection();
if(selection.length==0){
return false;
}
">
<Confirmation Message="确实要删除吗?" ConfirmRequest="True" BeforeConfirm="
var tree = App.tp_prov;
var selection = tree.getSelectionModel().getSelection();
if(selection.length==0){
Ext.Msg.alert('提示', '请选择地区');
return false;
}
">
</Confirmation>
</Click>
</DirectEvents>
</ext:Button>