Beispiel #1
0
        /// <summary>
        /// Generates the ControlSpecific JavaScript. This script is safe to
        /// allow multiple callbacks to run simultaneously.
        /// </summary>
        private void GenerateControlSpecificJavaScript()
        {
            // Figure out the initial URL we're going to
            // Either it's the provided URL from the control or
            // we're posting back to the current page
            string Url = null;

            if (ServerUrl == null || ServerUrl == "")
            {
                Url = Context.Request.Path;
            }
            else
            {
                Url = ResolveUrl(ServerUrl);
            }


            //Uri ExistingUrl = Context.Request.Url;

            //// Must fix up URL into fully qualified URL for XmlHttp
            //if (!ServerUrl.ToLower().StartsWith("http"))
            //    Url = ExistingUrl.Scheme + "://" + ExistingUrl.Authority + Url;

            string CallbackHandler = ClientCompleteHandler;

            if (string.IsNullOrEmpty(CallbackHandler))
            {
                CallbackHandler = "null";
            }

            string StartupCode =
                "function " + ClientID + @"_GetHoverPanel() {
    var hover = new HoverPanel(""#" + ClientID + @""");
    hover.serverUrl = """ + Url + @""";
    hover.timeout = " + Timeout.ToString() + @";
    hover.completed = " + CallbackHandler + @";
    hover.htmlTargetId = """ + (HtmlTargetClientId == "" ? ClientID : HtmlTargetClientId) + @""";
    hover.postbackMode = """ + PostBackMode.ToString() + @""";
    hover.navigateDelay = " + NavigateDelay.ToString() + @";
    hover.adjustWindowPosition = " + AdjustWindowPosition.ToString().ToLower() + @";
    hover.eventHandlerMode = """ + EventHandlerMode.ToString() + @""";
    hover.shadowOpacity = " + ShadowOpacity.ToString(CultureInfo.InvariantCulture.NumberFormat) + @";
    hover.shadowOffset = " + ShadowOffset + @";
    hover.hoverOffsetRight = " + HoverOffsetRight.ToString() + @";
    hover.hoverOffsetBottom = " + HoverOffsetBottom.ToString() + @";
    return hover;
}
$( function() { 
    window." + ClientID + " = " + ClientID + @"_GetHoverPanel();
});
";

            ScriptProxy.RegisterStartupScript(this, GetType(), ClientID + "_STARTUP", StartupCode, true);
        }
        /// <summary>
        /// Creates the JavaScript client side object that matches the
        /// server side method signature. The JScript function maps
        /// to a CallMethod() call on the client.
        /// </summary>
        private void GenerateClassWrapperForCallbackMethods()
        {
            if (ServiceType != AjaxMethodCallbackServiceTypes.AjaxMethodCallback)
            {
                GenerateClassWrapperForWcfAndAsmx();
                return;
            }

            StringBuilder sb = new StringBuilder();

            if (GenerateClientProxyClass == ProxyClassGenerationModes.jsdebug)
            {
                ClientScriptProxy.Current.RegisterClientScriptInclude(this, typeof(ControlResources), ServerUrl.ToLower() + "/jsdebug", ScriptRenderModes.Script);
                return;
            }
            if (GenerateClientProxyClass == ProxyClassGenerationModes.Inline)
            {
                Type objectType = null;

                if (ClientProxyTargetType != null)
                {
                    objectType = ClientProxyTargetType;
                }
                else if (TargetInstance != null)
                {
                    objectType = TargetInstance.GetType();
                }
                // assume Page as default
                else
                {
                    objectType = Page.GetType();
                }

                sb.Append("var " + ID + " = { ");

                MethodInfo[] Methods = objectType.GetMethods(BindingFlags.Instance | BindingFlags.Public);
                foreach (MethodInfo Method in Methods)
                {
                    if (Method.GetCustomAttributes(typeof(CallbackMethodAttribute), false).Length > 0)
                    {
                        sb.Append("\r\n    " + Method.Name + ": function " + "(");

                        string ParameterList = "";
                        foreach (ParameterInfo Parm in Method.GetParameters())
                        {
                            ParameterList += Parm.Name + ",";
                        }
                        sb.Append(ParameterList + "completed,errorHandler)");

                        sb.AppendFormat(
                            @"
    {{
        var _cb = {0}_GetProxy();
        _cb.callMethod(""{1}"",[{2}],completed,errorHandler);
        return _cb;           
    }},", ID, Method.Name, ParameterList.TrimEnd(','));
                    }
                }

                if (sb.Length > 0)
                {
                    sb.Length--; // strip trailing ,
                }
                // End of class
                sb.Append("\r\n}\r\n");
            }
            string Url = null;

            if (string.IsNullOrEmpty(ServerUrl))
            {
                Url = Context.Request.Path;
            }
            else
            {
                Url = ResolveUrl(ServerUrl);
            }

            sb.Append(
                "function " + ID + @"_GetProxy() {
    var _cb = new AjaxMethodCallback('" + ID + "','" + Url + @"',
                                    { timeout: " + Timeout.ToString() + @",
                                      postbackMode: '" + PostBackMode.ToString() + @"',
                                      formName: '" + PostBackFormName + @"' 
                                    });
    return _cb;
}
");
            ClientScriptProxy.RegisterStartupScript(this, GetType(), ID + "_ClientProxy", sb.ToString(), true);
        }