gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 12:13:31 24 4
gpt4 key购买 nike

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

这是我的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com