Beispiel #1
0
        public static string ReplaceAjaxMethods(string script, Control seed)
        {
            if (TokenUtils.IsAjaxMethodsToken(script))
            {
                UserControl parent = seed as UserControl;

                if (parent == null)
                {
                    parent = ReflectionUtils.GetTypeOfParent(seed, typeof(System.Web.UI.UserControl)) as UserControl;
                }

                ScriptManager sm = null;
                string        ns = "Coolite.AjaxMethods";

                if (parent != null)
                {
                    string id = ScriptManager.GetControlIdentification(parent);

                    if (!string.IsNullOrEmpty(id))
                    {
                        id = string.Concat(".", id);
                    }

                    sm = ScriptManager.GetInstance(HttpContext.Current);

                    if (sm != null)
                    {
                        ns = sm.AjaxMethodNamespace;
                    }

                    return(script.Replace(TokenUtils.AJAXMETHODS_PATTERN, string.Concat(ns, id)));
                }
                else
                {
                    Page parentPage = seed as Page;

                    if (parentPage == null)
                    {
                        parentPage = ReflectionUtils.GetTypeOfParent(seed, typeof(System.Web.UI.Page)) as System.Web.UI.Page;
                    }

                    if (parentPage != null)
                    {
                        sm = ScriptManager.GetInstance(parentPage);

                        if (sm != null)
                        {
                            ns = sm.AjaxMethodNamespace;
                        }

                        return(script.Replace(TokenUtils.AJAXMETHODS_PATTERN, ns));
                    }
                }
            }

            return(script);
        }