PDA

View Full Version : [CLOSED] confirm message in codebehind?



hdsoso
Sep 23, 2013, 3:16 PM
i code batch update in codebehind, when delete a record, I want to show a confirm message "are you sure to delete it?",
how to do it in codebehind?


protected void BatchUpdate(object sender, DirectEventArgs e)
{
ChangeRecords<model.crm.hdsoso.com.column> persons = new StoreDataHandler(e.ExtraParams["data"]).BatchObjectData<model.crm.hdsoso.com.column>();


foreach (model.crm.hdsoso.com.column deleted in persons.Deleted)
{
try
{
//here I want to show message,such as
// X.Msg.Confirm("alert","are you sure to delete?", callback fun) ??
_columnService.Delete(deleted);
}
catch (Exception)
{
X.Msg.Alert("消息", "删除失败").Show();
}
}

foreach (model.crm.hdsoso.com.column updated in persons.Updated)
{
try
{
_columnService.Update(updated);
}
catch (Exception)
{
X.Msg.Alert("消息", "更新失败").Show();
}

}

Daniil
Sep 23, 2013, 3:45 PM
Hi @hdsoso,


X.Msg.Confirm()
generates JavaScript code which gets executed when a browser gets a DirectEvent's response. "A browser gets a response" means that a DirectEvent's code behind handler execution is finished. There is no way to suspend a DirectEvent's code behind handler waiting for a user confirmation.

The best option in your case would be requesting a confirmation on client side before saving.

hdsoso
Sep 27, 2013, 4:38 AM
Hi @hdsoso,


X.Msg.Confirm()
generates JavaScript code which gets executed when a browser gets a DirectEvent's response. "A browser gets a response" means that a DirectEvent's code behind handler execution is finished. There is no way to suspend a DirectEvent's code behind handler waiting for a user confirmation.

The best option in your case would be requesting a confirmation on client side before saving.

because batchupdate method contains add,del,update , but i want to confirm only on del method.
now , i wrote a test case which i use extjs method, but how to convert json data to object.
json data is


[{"raw":{"id":5,"name":"s5"},"modified":{},"data":{"id":5,"name":"s5"},"hasListeners":{},"events":{},"directListeners":{},"hasDirectListeners":{},"stores":[],"internalId":5,"id":"ext-gen1025-5","phantom":false,"index":4,"store":null,"removedFrom":4}]

how to convert "data" to object.
my test case is


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm17.aspx.cs" Inherits="TobrosCWT.test.WebForm17" %>

<!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">
public class Student
{
public int id { get; set; }
public string name { get; set; }
}

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
store1.DataSource = new List<Student>()
{
new Student{id = 1,name = "s1"},
new Student{id = 2,name = "s2"},
new Student{id = 3,name = "s3"},
new Student{id = 4,name = "s4"},
new Student{id = 5,name = "s5"}
};
store1.DataBind();
}
}

[DirectMethod]
public void BatchDel(string del)
{
X.Msg.Alert("消息", "已删除").Show();
}
public void BatchUpd(string upd)
{
X.Msg.Alert("消息", "已更新").Show();
}

</script>
<script type="text/javascript">
var batchUpdate = function () {
var del = App.store1.getRemovedRecords();
if (del.length != 0) {
Ext.MessageBox.confirm("消息","确实要删吗?", function (btn) {
if (btn == 'yes') {
App.direct.BatchDel(del);
}
});
}
var upd = App.store1.getModifiedRecords();

}
</script>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server" SourceFormatting="True"></ext:ResourceManager>
<ext:GridPanel runat="server" ID="GridPanel1">
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" Text="批量更新" Icon="Disk">
<Listeners>
<Click Fn="batchUpdate"></Click>
</Listeners>
</ext:Button>
<ext:Button runat="server" Text="删除" Icon="Delete">
<Listeners>
<Click Handler="var selection = #{GridPanel1}.getView().getSelectionModel().getSel ection()[0];
if (selection) {
#{GridPanel1}.store.remove(selection);
}">
</Click>
</Listeners>
</ext:Button>
</Items>

</ext:Toolbar>
</TopBar>
<Store>
<ext:Store runat="server" ID="store1">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="id"></ext:ModelField>
<ext:ModelField Name="name"></ext:ModelField>
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel>
<Columns>
<ext:Column runat="server" DataIndex="id" Text="编号"></ext:Column>
<ext:Column runat="server" DataIndex="name" Text="名称">
<Editor>
<ext:TextField runat="server"></ext:TextField>
</Editor>
</ext:Column>
</Columns>
</ColumnModel>
<Plugins>
<ext:CellEditing runat="server"></ext:CellEditing>

</Plugins>
<SelectionModel>
<ext:RowSelectionModel runat="server" Mode="Multi" ID="RowSelectionModel1"></ext:RowSelectionModel>
</SelectionModel>
</ext:GridPanel>
</form>
</body>
</html>

Daniil
Sep 27, 2013, 1:00 PM
You can still use batch saving, but you should confirm all deletions before a save request.

In your example you can do the following:

var batchUpdate = function () {
var del = App.store1.getChangedData().Deleted;

if (del.length != 0) {
Ext.MessageBox.confirm("消息","确实要删吗?", function (btn) {
if (btn == 'yes') {
App.direct.BatchDel(del);
}
});
}
};


[DirectMethod]
public void BatchDel(string del)
{
List<Student> removedStudents = JSON.Deserialize<List<Student>>(del);
X.Msg.Alert("消息", removedStudents.Count).Show();
}