【发布时间】:2012-03-30 02:29:33
【问题描述】:
我正在尝试在这个网站上工作,我需要过滤要插入数据库的数据。例如,我需要将“Hello World”插入数据库。但是,它已经存在。因此,我需要弹出一个确认框,提示“数据库中已经存在字符串 Hello World。您确定要继续吗?”
我的问题是我不知道我应该在代码中的哪个位置包含我的确认消息。请参考以下内容:
private bool CheckData(string myString)
{
//Check database if myString already exists.
return;
}
private void btnSave_Click(Object sender, EventArgs e)
{
CheckData(myString)
//If the above is true, then the confirmation box should appear.
//Do something to save myString to the database.
}
我正在使用以下代码以编程方式将 OnClientClick 事件处理程序添加到我的按钮:
btnSave.OnClientClick = "confirmation('The string " + myString + " already exists in the database. Are you sure you want to continue?')";
我的问题基本上是处理这种情况的最佳方法是什么?由于我无法将此代码放在 btnSave_Click 事件上(它将添加 OnClientClick 处理程序,但只会在下次单击按钮时触发)。
【问题讨论】:
-
你可以使用 btnSave.OnClientClick="window.alert('your message')"
标签: c# asp.net confirmation onclientclick