Sunday, May 12, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
170
rated 0 times [  174] [ 4]  / answers: 1 / hits: 30370  / 15 Years ago, wed, august 5, 2009, 12:00:00

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.


More From » c#

 Answers
89

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.



Button code:



 <asp:Button ID=btnSave OnClick=btnSaveClick runat=server Text=Save OnClientClick=return CheckForVersion() />


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# 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;
}

[#98982] Monday, August 3, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
andrea

Total Points: 445
Total Questions: 95
Total Answers: 103

Location: Tonga
Member since Tue, Nov 30, 2021
3 Years ago
andrea questions
Mon, Feb 15, 21, 00:00, 3 Years ago
Thu, Dec 17, 20, 00:00, 3 Years ago
Thu, Jan 30, 20, 00:00, 4 Years ago
;