I just wanted to ask what is the best way to send email's on button click. My back end is in C# and front-end mainly in asp. I have simple table with few text boxes. I gather their values with jquery and send them via ajax to c# webmethod and then to database.
This is my front end part: https://jsfiddle.net/m8dLwf9z/85/
Ask you can see my button is pure html.
<input type="button" class="button" id="myButton" value="Save" />
This is my WebMethod where I take ajax values and send them to database with "Insert Object" stored procedure:
[WebMethod(EnableSession = true)]
public static int GetCollection(List<myCollection> omyCollection, int ddl, string lvl)
{ //Datatable is filled with foreach loop
DataTable tableMain = new DataTable();
tableMain.Columns.Add("CharID");
tableMain.Columns.Add("CharaValue");
foreach (myCollection mycol in omyCollection)
{
string label = mycol.label;
string opis = mycol.opis;
tableMain.Rows.Add(label, opis);
}
int success = 0;
string conn = ConfigurationManager.ConnectionStrings["Connection"].ConnectionString;
using (SqlConnection connection = new SqlConnection(conn))
try
{
//Check if values allready exist in the database
connection.Open();
SqlCommand cmdCount = new SqlCommand("getDuplicate", connection);
cmdCount.CommandType = CommandType.StoredProcedure;
cmdCount.Parameters.AddWithValue("@ObjectName", lvl);
var count = (string)cmdCount.ExecuteScalar();
if (count == null)
{
//Database insert
SqlCommand cmdProc = new SqlCommand("InsertObject", connection);
cmdProc.CommandType = CommandType.StoredProcedure;
//Parameters are sent to the database
cmdProc.Parameters.AddWithValue("@ObjectName", lvl);
cmdProc.Parameters.AddWithValue("@BCID", ddl);
cmdProc.Parameters.AddWithValue("@CharaValueParamether", tableMain);
cmdProc.ExecuteNonQuery();
//If the values are inserted send value 1 to ajax
success = 1;
}
else
{
}
}
catch
{
}
finally
{
connection.Close();
}
return success;
}
I think I have to have some webmethod c# code thats activated via ajax? Can someone give me some kind of help ?
Thanks in advance!