weixin_33696822 2018-07-19 13:18 采纳率: 0%
浏览 36

单击按钮发送电子邮件

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!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求解 yolo算法问题
    • ¥15 虚拟机打包apk出现错误
    • ¥30 最小化遗憾贪心算法上界
    • ¥15 用visual studi code完成html页面
    • ¥15 聚类分析或者python进行数据分析
    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝