Esempio n. 1
0
        /// <summary>
        /// Registers the client-side script.
        /// </summary>
        private void RegisterClientScript()
        {
            ClientScriptManager csm = this.Page.ClientScript;

            // Register a hidden field which will hold the changes made on the clientside.
            csm.RegisterHiddenField("webPartLayoutChanges", String.Empty);

            // Register the webpart manager script.
            csm.RegisterClientScriptResource(this.GetType(), "Wilco.Web.Resources.WebPartManager.js");

            // Register the initialization script.
            StringBuilder script = new StringBuilder();

            script.Append("var webPartPageFormName = document.forms[0].id;");
            script.AppendFormat("WebPartSetupLayoutFlags('{0}', '{1}');\r\n", this.DragObjectCssClass, this.SplitterObjectCssClass);
            csm.RegisterStartupScript(this.GetType(), "WebPartManager_Init", script.ToString(), true);

            StringBuilder zoneArray = new StringBuilder();

            for (int i = 0; i < this.zones.Count; i++)
            {
                if (i > 0)
                {
                    zoneArray.Append(',');
                }
                zoneArray.AppendFormat("new Array('{0}', '{1}', '{2}')", this.zones[i].ClientID, this.zones[i].CssClass, this.zones[i].DragCssClass);
            }

            csm.RegisterArrayDeclaration("webPartZones", zoneArray.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// 向System.Web.UI.Page 注册一个隐藏值
        /// </summary>
        /// <param name="page">System.Web.UI.Page</param>
        /// <param name="hiddenFieldName">要注册的隐藏字段的名称</param>
        /// <param name="HiddenFieldInitialValue">要注册的字段的初始值</param>
        public static void JsHiddenField(Page page, string hiddenFieldName, string HiddenFieldInitialValue)
        {
            // Get a ClientScriptManager reference from the Page class.
            ClientScriptManager clientScript = page.ClientScript;

            clientScript.RegisterHiddenField(hiddenFieldName, HiddenFieldInitialValue);
        }
Esempio n. 3
0
        public static void RegisterHiddenField(Page p)
        {
            ClientScriptManager cs = p.ClientScript;
            // Define the hidden field name and initial value.
            String hiddenName  = "MyHiddenField";
            String hiddenValue = "3";

            // Register the hidden field with the Page class.
            cs.RegisterHiddenField(hiddenName, hiddenValue);
        }
Esempio n. 4
0
        private void RegisterScrollScript()
        {
            if (this.Page == null)
            {
                return;
            }
            MultiViewBar parent = this.Parent as MultiViewBar;

            if (parent == null || !parent.EnableClientScript)
            {
                return;
            }

            ClientScriptManager script = this.Page.ClientScript;

            script.RegisterHiddenField(this.ScrollXName, this.scrollX);
            script.RegisterHiddenField(this.ScrollYName, this.scrollY);

            script.RegisterClientScriptResource(typeof(MultiViewItem), "MetaBuilders.WebControls.Embedded.MultiViewItemScript.js");

            script.RegisterStartupScript(typeof(MultiViewItem), "startup", "MetaBuilders_MultiViewItem_Init(); " + String.Format(Resources.AjaxWorkaroundScript, "MetaBuilders_MultiViewItem_Init"), true);
            script.RegisterArrayDeclaration("MetaBuilders_MultiViewItems", "'" + this.ClientID + "_ScrollArea'");
        }
Esempio n. 5
0
        /// <summary>
        /// Call this method on page's "SavePageStateToPersistenceMedium" method
        /// </summary>
        /// <param name="clientScript">ClientScript object of page</param>
        /// <param name="viewState">parameter of "SavePageStateToPersistenceMedium" method</param>
        public static void CompressViewState(ClientScriptManager clientScript, object viewState, int splitSize = 4000)
        {
            LosFormatter formatter = new LosFormatter();
            StringWriter writer    = new StringWriter();

            formatter.Serialize(writer, viewState);
            string viewStateString = writer.ToString();

            byte[] bytes = Convert.FromBase64String(viewStateString);
            bytes = Compress(bytes);
            int byteSplitSize = splitSize / 4 * 3;

            for (int i = 0; i <= bytes.Length / byteSplitSize; i++)
            {
                int    offset = i * byteSplitSize;
                string base64 = Convert.ToBase64String(bytes, offset, Math.Min(byteSplitSize, bytes.Length - offset));
                clientScript.RegisterHiddenField("__VSTATE" + i, base64);
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            String arrName  = "MyArray";
            String arrValue = "\"1\", \"2\", \"text\"";

            // Define the hidden field name and initial value.
            String hiddenName  = "MyHiddenField";
            String hiddenValue = "3";


            // Get a ClientScriptManager reference from the Page class.
            ClientScriptManager cs = Page.ClientScript;

            // Register the array with the Page class.
            cs.RegisterArrayDeclaration(arrName, arrValue);

            // Register the hidden field with the Page class.
            cs.RegisterHiddenField(hiddenName, hiddenValue);
        }
Esempio n. 7
0
        /// <summary>
        /// Builds the scripts.
        /// </summary>
        private void BuildScripts()
        {
            try
            {
                IButtonControl btn = (IButtonControl)this.Parent.FindControl(this.CropButtonID);
                btn.Click += new EventHandler(btn_Click);
            }
            catch
            {
                throw new NullReferenceException("Please set CropButtonID property, it can be either linkbutton or button control. [" + this.ID.ToString() + "]");
            }

            string aPath = HttpContext.Current.Request.Url.AbsolutePath.Replace(
                HttpContext.Current.Request.Url.Segments[HttpContext.Current.Request.Url.Segments.Length - 1], "");

            this.APath = aPath;

            ClientScriptManager cs = Page.ClientScript;

            if (this.IncludeJQuery)
            {
                if (string.IsNullOrEmpty(this.ScriptPath))
                {
                    this.ScriptPath = APath + "scripts/";
                }
                if (!cs.IsClientScriptIncludeRegistered(this.GetType(), "jquery"))
                {
                    cs.RegisterClientScriptInclude(this.GetType()
                                                   , "jquery", ResolveClientUrl(this.ScriptPath + "jquery.js"));
                }

                if (!cs.IsClientScriptIncludeRegistered(this.GetType(), "jqueryCrop"))
                {
                    cs.RegisterClientScriptInclude(this.GetType()
                                                   , "jqueryCrop", ResolveClientUrl(this.ScriptPath + "jquery.jcrop.js"));
                }
            }

            //bool cropInitScriptAdded = cs.IsClientScriptBlockRegistered("cropInit");
            cs.RegisterHiddenField("_x_" + this.ClientID, this.x.ToString());
            cs.RegisterHiddenField("_y_" + this.ClientID, this.y.ToString());
            cs.RegisterHiddenField("_w_" + this.ClientID, this.w.ToString());
            cs.RegisterHiddenField("_h_" + this.ClientID, this.h.ToString());

            if (true)
            {
                Image image = (Image)this.Parent.FindControl(cropimage);
                ViewState["imagePath"] = image.ImageUrl;

                StringBuilder sb = new StringBuilder();
                sb.Append("<script>");
                sb.Append("$(function(){");


                int x = X; int y = Y; int w = W == 0 ? 15 : W; int h = H == 0 ? 15 : H;

                sb.Append("$('#" + image.ClientID + "').Jcrop({" +
                          "setSelect: [" + x.ToString() + "," + y.ToString() + "," + w.ToString() + ", " + h.ToString() + "]" +
                          ", onChange: __showPreview_" + this.ClientID);


                if (!string.IsNullOrEmpty(this.Ratio))
                {
                    sb.Append(", aspectRatio: " + this.Ratio);
                }

                if (!string.IsNullOrEmpty(this.MaxSize))
                {
                    sb.Append(", maxSize: [" + this.MaxSize + "]");
                }

                if (!string.IsNullOrEmpty(this.MinSize))
                {
                    sb.Append(", minSize: [" + this.MinSize + "]");
                }



                sb.Append("});");

                sb.Append("});");

                sb.Append("function __showPreview_" + this.ClientID + " (coords){" +
                          "$('#_x_" + this.ClientID + "').val(coords.x);" +
                          "$('#_y_" + this.ClientID + "').val(coords.y);" +
                          "$('#_w_" + this.ClientID + "').val(coords.w);" +
                          "$('#_h_" + this.ClientID + "').val(coords.h);" +
                          "}");

                sb.Append("</script>");
                this.script = sb.ToString();
            }
        }
Esempio n. 8
0
        private void crearCampoOcultoPerfil(string perfil)
        {
            ClientScriptManager campo = Page.ClientScript;

            campo.RegisterHiddenField("OcultoPerfil", perfil);
        }
Esempio n. 9
0
        private void crearCampoOcultoNombre(string nombre)
        {
            ClientScriptManager campo = Page.ClientScript;

            campo.RegisterHiddenField("OcultoNombre", nombre);
        }
 /// <summary>
 /// Registers a hidden value with the <see cref="T:System.Web.UI.Page"/> object.
 /// </summary>
 /// <param name="hiddenFieldName">The name of the hidden field to register.
 /// </param><param name="hiddenFieldInitialValue">The initial value of the field to register.
 /// </param><exception cref="T:System.ArgumentNullException"><paramref name="hiddenFieldName"/> is null.
 /// </exception>
 public void RegisterHiddenField(string hiddenFieldName, string hiddenFieldInitialValue)
 {
     _clientScriptManager.RegisterHiddenField(hiddenFieldName, hiddenFieldInitialValue);
 }
Esempio n. 11
0
        /// <summary>
        ///
        /// </summary>
        protected override void CreateChildControls()
        {
            bool isInUpdatePanel = this.IsInUpdatePanel;


            //Page p = (Page)System.Web.HttpContext.Current.Handler;
            //ScriptManager m = ScriptManager.GetCurrent(p);



            ClientScriptManager cs = Page.ClientScript;

            if (this.IncludeJQuery)
            {
                if (string.IsNullOrEmpty(this.ScriptPath))
                {
                    this.ScriptPath = "/scripts/";
                }

                if (isInUpdatePanel)
                {
                    if (!cs.IsClientScriptIncludeRegistered(this.GetType(), "jquery"))
                    {
                        ScriptManager.RegisterClientScriptInclude(this, this.GetType()
                                                                  , "jquery", ResolveClientUrl(this.ScriptPath + "jquery.js"));
                    }

                    if (!cs.IsClientScriptIncludeRegistered(this.GetType(), "jqueryCrop"))
                    {
                        ScriptManager.RegisterClientScriptInclude(this, this.GetType()
                                                                  , "jqueryCrop", ResolveClientUrl(this.ScriptPath + "jquery.jcrop.js"));
                    }
                }
                else
                {
                    if (!cs.IsClientScriptIncludeRegistered(this.GetType(), "jquery"))
                    {
                        cs.RegisterClientScriptInclude(this.GetType()
                                                       , "jquery", ResolveClientUrl(this.ScriptPath + "jquery.js"));
                    }

                    if (!cs.IsClientScriptIncludeRegistered(this.GetType(), "jqueryCrop"))
                    {
                        cs.RegisterClientScriptInclude(this.GetType()
                                                       , "jqueryCrop", ResolveClientUrl(this.ScriptPath + "jquery.jcrop.js"));
                    }
                }
            }
            else
            {
                // load it from google ajax library. Faster way and less annoying!

                /*if(!cs.IsClientScriptIncludeRegistered("jquery"))
                 *  cs.RegisterClientScriptInclude("jquery"
                 *      , "http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js");
                 */

                string jquery = "\r\n<script src=\"" + cs.GetWebResourceUrl(this.GetType(),
                                                                            "CS.Web.UI.jquery.js") + "\" type=\"text/javascript\"></script>\r\n";

                string cropJS = "\r\n<script src=\"" + cs.GetWebResourceUrl(this.GetType(),
                                                                            "CS.Web.UI.jquery.jcrop.js") + "\" type=\"text/javascript\"></script>\r\n";


                if (isInUpdatePanel)
                {
                    if (!cs.IsClientScriptBlockRegistered("jquery"))
                    {
                        cs.RegisterClientScriptBlock(this.GetType(), "jquery", jquery, false);
                    }

                    if (!cs.IsClientScriptBlockRegistered("cropJS"))
                    {
                        cs.RegisterClientScriptBlock(this.GetType(), "cropJS", cropJS, false);
                    }
                }
                else
                {
                    if (!cs.IsClientScriptBlockRegistered("jquery"))
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "jquery", jquery, false);
                    }

                    if (!cs.IsClientScriptBlockRegistered("cropJS"))
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "cropJS", cropJS, false);
                    }
                }
            }



            string cropCss = "<link href=\"" + cs.GetWebResourceUrl(this.GetType(),
                                                                    "CS.Web.UI.jquery.jcrop.css") + "\" type=\"text/css\" rel=\"stylesheet\" />\r\n";

            //if (!Page.Header.Controls.Add(new LiteralControl(("cropCss"))
            //    cs.RegisterStartupScript(this.GetType(), "cropCss", cropCss, false);

            if (!cs.IsClientScriptBlockRegistered("cropJS"))
            {
                Page.Header.Controls.Add(new LiteralControl(cropCss));
            }

            //bool cropInitScriptAdded = cs.IsClientScriptBlockRegistered("cropInit");

            if (true)
            {
                System.Web.UI.WebControls.Image image =
                    (System.Web.UI.WebControls.Image)Parent.FindControl(cropimage);
                ViewState["ImageUrl"] = image.ImageUrl;


                //System.Drawing.Image img =
                //    System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath( image.ImageUrl));


                //check if we set canvas size
                if (this.CanvasHeight > 0 | this.CanvasWidth > 0)
                {
                    string folder = HttpContext.Current.Server.MapPath("~/");
                    GetRawSize(folder + image.ImageUrl);

                    double rratio = (double)rawHeight / rawWidth; //raw image ratio
                    double cratio;                                //canvas ratio
                    if (this.CanvasHeight == 0)
                    {
                        cratio            = rratio;
                        this.CanvasHeight = Convert.ToInt32(this.CanvasWidth * rratio);
                    }
                    else if (this.CanvasWidth == 0)
                    {
                        cratio           = rratio;
                        this.CanvasWidth = Convert.ToInt32(this.CanvasHeight / rratio);
                    }
                    else
                    {
                        cratio = (double)CanvasHeight / CanvasWidth;
                    }
                    if (rratio > cratio)
                    {//we have to fit height
                        if (rawHeight > CanvasHeight)
                        {
                            resizefact   = (double)CanvasHeight / rawHeight;
                            image.Height = CanvasHeight;
                            image.Width  = Convert.ToInt32(rawWidth * resizefact);
                        }
                    }
                    else
                    { //we have to fit width
                        if (rawWidth > CanvasWidth)
                        {
                            resizefact   = (double)CanvasWidth / rawWidth;
                            image.Width  = CanvasWidth;
                            image.Height = Convert.ToInt32(rawHeight * resizefact);
                        }
                    }
                    ViewState["canvasRatio"] = resizefact;
                }

                StringBuilder sb = new StringBuilder();

                sb.Append("<script>$(function(){ ");

                string showPreviewScript = "";

                showPreviewScript = ", onChange: __showPreview" +
                                    ", onSelect: __showPreview";


                sb.Append("$('#" + image.ClientID + "').Jcrop({" +
                          "setSelect: [" + X.ToString() + "," +
                          Y.ToString() + "," +
                          X2.ToString() + ", " +
                          Y2.ToString() + "]" +
                          showPreviewScript);


                if (!string.IsNullOrEmpty(this.Ratio))
                {
                    sb.Append(", aspectRatio: " + this.Ratio);
                }

                if (!string.IsNullOrEmpty(this.MaxSize))
                {
                    sb.Append(", maxSize: [" + this.MaxSize + "]");
                }

                if (!string.IsNullOrEmpty(this.MinSize))
                {
                    sb.Append(", minSize: [" + this.MinSize + "]");
                }

                sb.Append("});");
                sb.Append("});");


                string script = @"function __showPreview(coords){                        

                            try{
                                    
                                    $('#_x').val(coords.x); 
                                    $('#_y').val(coords.y); 
                                    $('#_w').val(coords.w);
                                    $('#_h').val(coords.h); 

                                    var rx = {1} / coords.w;
	                                var ry = {2} / coords.h;

	                                $('#{0}').css({
		                                width: Math.round(rx * {3}) + 'px',
		                                height: Math.round(ry * {4}) + 'px',
		                                marginLeft: '-' + Math.round(rx * coords.x) + 'px',
		                                marginTop: '-' + Math.round(ry * coords.y) + 'px'
	                                });

                            }
                            catch(e){} 
                                                                                      
                        }
                            
                        ";


                GetRawSize(image.ImageUrl);


                script = script.Replace("{0}", this.PreviewImageID);
                script = script.Replace("{1}", rawWidth.ToString());
                script = script.Replace("{2}", rawHeight.ToString());
                script = script.Replace("{3}", rawWidth.ToString());
                script = script.Replace("{4}", rawHeight.ToString());

                sb.Append(script);

                //sb.Append(string.Format(script.ToString(),this.PreviewImageID));



                //if (EnablePreview)
                //{
                //    sb.Append("\r\n function __showPreview22(coords){ \r\n" +
                //                "var rx = 100 / coords.w; \r\n" +
                //                "var ry = 100 / coords.h; \r\n" +
                //                "$('#preview').css({" +
                //                "    width: Math.round(rx * " + img.Width + ") + 'px', \r\n" +
                //                "    height: Math.round(ry * " + img.Height + ") + 'px', \r\n" +
                //                "    marginLeft: '-' + Math.round(rx * coords.x) + 'px', \r\n" +
                //                "    marginTop: '-' + Math.round(ry * coords.y) + 'px' \r\n" +
                //                "});  try {__showDebug(coords); } catch(e) {}}\r\n\r\n");
                //}


                /*sb.Append(@"function __showDebug(coords){
                 *          try{
                 *              $('#wci_xt').val(coords.x);
                 *              $('#wci_yt').val(coords.y);
                 *              $('#wci_wt').val(coords.w);
                 *              $('#wci_ht').val(coords.h);
                 *          }
                 *          catch(e){}
                 *      }");
                 *
                 */

                sb.Append(@"</script>");


                if (isInUpdatePanel)
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType()
                                                            , "cropInit"
                                                            , sb.ToString(), false);


                    //ScriptManager.RegisterStartupScript(this, this.GetType(), "alertbabam", "alert('test');", true);

                    ScriptManager.RegisterHiddenField(this, "_x", X.ToString());
                    ScriptManager.RegisterHiddenField(this, "_y", Y.ToString());
                    ScriptManager.RegisterHiddenField(this, "_w", W.ToString());
                    ScriptManager.RegisterHiddenField(this, "_h", H.ToString());
                }
                else
                {
                    cs.RegisterClientScriptBlock(this.GetType()
                                                 , "cropInit"
                                                 , sb.ToString(), false);


                    cs.RegisterHiddenField("_x", X.ToString());
                    cs.RegisterHiddenField("_y", Y.ToString());
                    cs.RegisterHiddenField("_w", W.ToString());
                    cs.RegisterHiddenField("_h", H.ToString());
                }



                image.Dispose();
                //img.Dispose();
            }

            base.CreateChildControls();

            //HttpContext.Current.Response.Write("ssss");
        }