Access the ScriptManager to alert in an action handler
Hi,
I have a action handler which stops people deleting certain types of DocumentType.
I would like to alert to tell the user why this cannot be deleted (and stop the tree from being reloaded). Can anyone point me in the correct direction regaridng this?
Here is my code which does not alert:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using umbraco.BusinessLogic; using umbraco.cms.businesslogic; using umbraco.cms.businesslogic.web; using System.Web;
namespace umbraco_ext { public class BasePage : System.Web.UI.Page {
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
}
}
public class AppBase : umbraco.BusinessLogic.ApplicationBase {
public AppBase() { Document.BeforeMoveToTrash += new Document.MoveToTrashEventHandler(Document_BeforeMoveToTrash);
I should also mention this does no compile as I get the following error:
Member 'System.Web.UI.ScriptManager.RegisterStartupScript(System.Web.UI.Page, System.Type, string, string, bool)' cannot be accessed with an instance reference; qualify it with a type name instead
you can't do it this way, registering startup scripts has to happen somewhere in the init method. Have you tried simply using response.write()?
You might also be able to separate the call from the declaration by adding a function RaiseAlert(alert) using RegisterStartupScript somewhere in an init method and then calling it via response.write ("<script>RaiseAlert('alert!!');</script>");
Access the ScriptManager to alert in an action handler
Hi,
I have a action handler which stops people deleting certain types of DocumentType.
I would like to alert to tell the user why this cannot be deleted (and stop the tree from being reloaded). Can anyone point me in the correct direction regaridng this?
Here is my code which does not alert:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic;
using umbraco.cms.businesslogic.web;
using System.Web;
namespace umbraco_ext
{
public class BasePage : System.Web.UI.Page
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
}
}
public class AppBase : umbraco.BusinessLogic.ApplicationBase
{
public AppBase()
{
Document.BeforeMoveToTrash += new Document.MoveToTrashEventHandler(Document_BeforeMoveToTrash);
}
void Document_BeforeMoveToTrash(Document sender, MoveToTrashEventArgs e)
{
e.Cancel = true;
Document obj = new Document(sender.Id);
Type csType = this.GetType();
System.Web.UI.ScriptManager.GetCurrent(((BasePage)obj.HttpContext.CurrentHandler)).(((BasePage)obj.HttpContext.CurrentHandler), ((BasePage)obj.HttpContext.CurrentHandler).GetType(), "msg", "alert('djd');", true);
}
}
}
Any help would be much appreciated.
Thanks
Scott
I should also mention this does no compile as I get the following error:
Member 'System.Web.UI.ScriptManager.RegisterStartupScript(System.Web.UI.Page, System.Type, string, string, bool)' cannot be accessed with an instance reference; qualify it with a type name instead
Thanks
Scot
Hi Scot,
you can't do it this way, registering startup scripts has to happen somewhere in the init method. Have you tried simply using response.write()?
You might also be able to separate the call from the declaration by adding a function RaiseAlert(alert) using RegisterStartupScript somewhere in an init method and then calling it via response.write ("<script>RaiseAlert('alert!!');</script>");
Hope that helps,
Sascha
is working on a reply...