Hi:
I have a RadGrid, the Radgrid contains a form template, his control are binding to a SqlDataSource.
When insert an element sends a mail (with .net libraries) into a mail that the user have inserted in a specific field.
The code works fine, but when the user introduce a invalid mail like 'badmail@badmail.com' when the user press insert button, send of mail fail (I manage the error in the event), radgrid shows what happen, but all fields are empty.
The code is the following
01.
protected
void
SqlDataSource1_Inserting(
object
sender, SqlDataSourceCommandEventArgs e)
02.
{
03.
04.
05.
06.
SqlDataSource1_Inserted
07.
DbCommand command = e.Command;
08.
DbConnection cx = command.Connection;
09.
cx.Open();
10.
DbTransaction tx = cx.BeginTransaction();
11.
command.Transaction = tx;
12.
}
13.
14.
15.
16.
17.
protected
void
SqlDataSource1_Inserted(
object
sender, SqlDataSourceStatusEventArgs e)
18.
{
19.
try
20.
{
21.
DbCommand command = e.Command;
22.
DbTransaction tx = command.Transaction;
23.
//Here code that sends email, process can fail.
24.
tx.Commit();
25.
}
26.
catch
(Exception exception)
27.
{
28.
tx.Rollback();
29.
throw
exception;
30.
}
31.
}
32.
33.
protected
void
RadGrid1_ItemInserted(
object
source, Telerik.WebControls.GridInsertedEventArgs e)
34.
{
35.
if
(e.Exception !=
null
)
36.
{
37.
e.ExceptionHandled =
true
;
38.
e.KeepInInsertMode =
true
;
39.
//Display a message to show the error
40.
}
41.
}
I whish that when the sent of mail fails, all the data of the form were preserve ¿Is it possible?
Thanks.