单击按钮发送电子邮件

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!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐