c# - 带有是或否按钮的 JavaScript 警报

标签 c# javascript asp.net

我想用是或否按钮显示警报。

这是我的 C# 代码:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Collections;
using System.Windows.Forms;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DialogResult dialogResult = MessageBox.Show("Sure", "Some Title", MessageBoxButtons.YesNo);
        if (dialogResult == DialogResult.Yes)
        {
            OleDbConnection con = new OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0;data source= C:/Users/xyz/Documents/Visual Studio 2010/WebSites/accesspassword/stud.accdb;Jet OLEDB:Database Password=12345;");
            con.Open();

            OleDbCommand com = new OleDbCommand("insert into Table1 values(@Roll,@f_name)", con);
            OleDbParameter obj1 = new OleDbParameter("@Roll", DbType.StringFixedLength);
            obj1.Value = TextBox1.Text;
            com.Parameters.Add(obj1);

            OleDbParameter obj2 = new OleDbParameter("@f_name", DbType.StringFixedLength);
            obj2.Value = TextBox2.Text;
            com.Parameters.Add(obj2);

            com.ExecuteNonQuery();
            TextBox1.Text = "";
            TextBox2.Text = "";
            con.Close();
        }
        else if (dialogResult == DialogResult.No)
        {
            TextBox2.Text = "";
        }
    }
}

此代码运行良好,但我想使用 JavaScript 警报和是或否按钮来执行此操作。 我正在使用 Visual Studio 2010 asp.net c#。

最佳答案

  <asp:Button ID="btn" runat="server" Text="High"
  OnClick="Button1_Click" OnClientClick="return AalertFunction();" />

Java 脚本:

     <script>     
        function AalertFunction() {
            if (confirm('Are you sure you want to save this thing into the database?')) {
                return;
            } else {
                return false;
            }
        }
    </script>

关于c# - 带有是或否按钮的 JavaScript 警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24840577/

相关文章:

c# - EF Core 查询 - 有没有办法按字母顺序查找下一个和上一个项目?

javascript - Google Analytics Embed API 不显示图表

javascripting 哪个网站接受发布javascript

javascript - <form> 和 Jquery ajax 错误

c# - 如何防止 session 超时

C# 参数计数不匹配将列表转换为数据表

c# - Entity Framework : Issue with IDENTITY_INSERT - "Cannot insert explicit value for identity column in table"

asp.net - SYBASE ODBC .Net 核心

c# - ds.Tables[0].Select() 代表什么

c# - 不同表同同