Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • SinkyPars 132 posts 175 karma points
    Sep 09, 2010 @ 13:54
    SinkyPars
    0

    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

  • SinkyPars 132 posts 175 karma points
    Sep 09, 2010 @ 14:02
    SinkyPars
    0

    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

  • Sascha Wolter 615 posts 1101 karma points
    Sep 09, 2010 @ 14:53
    Sascha Wolter
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft