在asp.net运行时的确认对话框 [英] Confirmation dialog at runtime in asp.net
问题描述
我有一个存储由页面名称和版本的网页一个简单的内容管理系统。点击保存,我的code(服务器端)检查页面名称/版本后存在。
I have a simple content management system that stores pages by Pagename and Version. After clicking on Save, my code (server side) checks for the existence of Pagename/Version.
如果它存在,我想显示一个确认对话框,要求用户确认当前页面名称/版本是否应该更换。
If it exists I would like to display a confirmation dialog box, which asks the user to confirm whether or not the current Pagename/Version should be replaced.
什么是实现这一目标的最简单的方法?谢谢。
What is the easiest way to accomplish this? Thanks.
推荐答案
我AP preciate既previous答案,他们是有用的,但不正是我一直在寻找。考虑到反应和做更多的研究,我张贴我的解决方案,这样也许这将帮助别人之后。
I appreciate both previous answers and they were helpful but not exactly what I was looking for. After considering the responses and doing more research I'm posting my solution so that maybe it will help someone else.
按钮code:
<asp:Button ID="btnSave" OnClick="btnSaveClick" runat="server" Text="Save" OnClientClick="return CheckForVersion()" />
使用Javascript:
Javascript:
<script language="javascript">
function CheckForVersion() {
PageMethods.CheckForVersion(aspnetForm.ctl00$ContentPlaceHolder1$ddlPageName2.value, aspnetForm.ctl00$ContentPlaceHolder1$txtContentName2.value, OnSucceeded, OnFailed);
return false;
}
function OnSucceeded(results) {
if(results) {
//version exists so prompt user
if(confirm("Version already exists. Do you want to overwrite?")) {
__doPostBack('ctl00$ContentPlaceHolder1$btnSave','');
}
}
else
{
//version does not exist so save it without prompting user
__doPostBack('ctl00$ContentPlaceHolder1$btnSave','');
}
}
function OnFailed(error) {
// handle pagemethod error
alert(error.get_message());
}
</script>
使用C#2.1亚音速:
C# using Subsonic 2.1:
[WebMethod]
public static bool CheckForVersion(string pageName, string versionName)
{
PageContentCollection pages = new PageContentCollection().Where("pageName", pageName).Where("versionName", versionName).Load();
if (pages.Count > 0)
return true;
else
return false;
}
这篇关于在asp.net运行时的确认对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!