示例#1
0
        /// <summary>
        /// Renders the contents inside the control begin and end tags.
        /// </summary>
        protected override void RenderContents(IHtmlWriter writer, RenderContext context)
        {
            if (RenderOnServer)
            {
                // render items
                bool first = true;
                foreach (var item in GetIEnumerableFromDataSource(DataSource))
                {
                    var value = string.IsNullOrEmpty(ValueMember) ? item : ReflectionUtils.GetObjectProperty(item, ValueMember);
                    var text = string.IsNullOrEmpty(DisplayMember) ? item : ReflectionUtils.GetObjectProperty(item, DisplayMember);

                    if (first)
                    {
                        writer.WriteUnencodedText(Environment.NewLine);
                        first = false;
                    }
                    writer.WriteUnencodedText("    ");  //Indent
                    writer.AddAttribute("value", value != null ? value.ToString() : "");
                    writer.RenderBeginTag("option");
                    writer.WriteText(text != null ? text.ToString() : "");
                    writer.RenderEndTag();
                    writer.WriteUnencodedText(Environment.NewLine);
                }
            }
        }
示例#2
0
 /// <summary>
 /// Renders the contents inside the control begin and end tags.
 /// </summary>
 protected override void RenderContents(IHtmlWriter writer, RenderContext context)
 {
     // render template
     writer.AddKnockoutDataBind("text", "errorMessage");
     writer.RenderBeginTag("li");
     writer.RenderEndTag();
 }
示例#3
0
        protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context)
        {
            writer.AddAttribute("class", "form-horizontal");
            writer.AddAttribute("role", "form");

            base.AddAttributesToRender(writer, context);
        }
示例#4
0
        /// <summary>
        /// Adds all attributes that should be added to the control begin tag.
        /// </summary>
        protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context)
        {
            if (!RenderOnServer)
            {
                writer.AddKnockoutDataBind("options", this, DataSourceProperty, () => { });

                if (!string.IsNullOrEmpty(DisplayMember))
                {
                    writer.AddKnockoutDataBind("optionsText", KnockoutHelper.MakeStringLiteral(DisplayMember));
                }
                if (!string.IsNullOrEmpty(ValueMember))
                {
                    writer.AddKnockoutDataBind("optionsValue", KnockoutHelper.MakeStringLiteral(ValueMember));
                }
            }

            // changed event
            var selectionChangedBinding = GetCommandBinding(SelectionChangedProperty);
            if (selectionChangedBinding != null)
            {
                writer.AddAttribute("onchange", KnockoutHelper.GenerateClientPostBackScript(selectionChangedBinding, context, this));
            }

            // selected value
            writer.AddKnockoutDataBind("value", this, SelectedValueProperty, () => { });

            base.AddAttributesToRender(writer, context);
        }
示例#5
0
        protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context)
        {
            AddEventAttributeToRender(writer, context, "onclick", ClickProperty);

            AddEventAttributeToRender(writer, context, "onchange", ValueChangedProperty);

            base.AddAttributesToRender(writer, context);
        }
示例#6
0
 private void AddEventAttributeToRender(IHtmlWriter writer, RenderContext context, string name, RedwoodProperty property)
 {
     var binding = GetCommandBinding(property);
     if (binding != null)
     {
         writer.AddAttribute(name, KnockoutHelper.GenerateClientPostBackScript(binding, context, this));
     }
 }
示例#7
0
 /// <summary>
 /// Renders the control into the specified writer.
 /// </summary>
 protected override void RenderControl(IHtmlWriter writer, RenderContext context)
 {
     // render resource links
     var resources = context.ResourceManager.GetResourcesInOrder().Where(r => r.GetRenderPosition() == ResourceRenderPosition.Head);
     foreach (var resource in resources)
     {
         resource.Render(writer);
     }
 }
示例#8
0
        /// <summary>
        /// Adds all attributes that should be added to the control begin tag.
        /// </summary>
        protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context)
        {
            var expression = KnockoutHelper.GetValidationTargetExpression(this, true);
            if (expression != null)
            {
                writer.AddKnockoutDataBind("foreach", expression + ".$validationErrors");
            }

            base.AddAttributesToRender(writer, context);
        }
示例#9
0
 public static void WriteRouteLinkHrefAttribute(string routeName, HtmlGenericControl control, IHtmlWriter writer, RenderContext context)
 {
     if (!control.RenderOnServer)
     {
         writer.AddKnockoutDataBind("attr", "{ href: " + GenerateKnockoutHrefExpression(routeName, control, context) + "}");
     }
     else
     {
         writer.AddAttribute("href", EvaluateRouteUrl(routeName, control, context));
     }
 }
示例#10
0
        protected override void RenderContents(IHtmlWriter writer, RenderContext context)
        {
            RenderLabel(writer);

            writer.AddAttribute("class", "col-sm-10");
            writer.RenderBeginTag("div");

            RenderChildren(writer, context);

            writer.RenderEndTag();
        }
示例#11
0
        /// <summary>
        /// Adds all attributes that should be added to the control begin tag.
        /// </summary>
        protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context)
        {
            TagName = WrapperTagName;

            if (!RenderOnServer)
            {
                writer.AddKnockoutForeachDataBind(GetDataSourceBinding().TranslateToClientScript(this, DataSourceProperty));
            }

            base.AddAttributesToRender(writer, context);
        }
示例#12
0
        /// <summary>
        /// Adds all attributes that should be added to the control begin tag.
        /// </summary>
        protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context)
        {
            writer.AddKnockoutDataBind("enable", this, EnabledProperty, () =>
            {
                if (!Enabled)
                {
                    writer.AddAttribute("disabled", "disabled");
                }
            });

            base.AddAttributesToRender(writer, context);
        }
示例#13
0
        protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context)
        {
            if (!RenderOnServer)
            {
                if (!string.IsNullOrWhiteSpace(EmptyItemText))
                {
                    writer.AddKnockoutDataBind("optionsCaption", KnockoutHelper.MakeStringLiteral(EmptyItemText));
                }
            }

            base.AddAttributesToRender(writer, context);
        }
示例#14
0
        public static string GenerateKnockoutHrefExpression(string routeName, HtmlGenericControl control, RenderContext context)
        {
            var link = GenerateRouteLinkCore(routeName, control, context);

            if ((bool)control.GetValue(Internal.IsSpaPageProperty))
            {
                return string.Format("'#!/' + {0}", link);
            }
            else
            {
                return string.Format("'{0}' + {1}", context.RequestContext.TranslateVirtualPath("~/"), link);
            }
        }
示例#15
0
        public static string EvaluateRouteUrl(string routeName, HtmlGenericControl control, RenderContext context)
        {
            var coreUrl = GenerateRouteUrlCore(routeName, control, context);

            if ((bool)control.GetValue(Internal.IsSpaPageProperty))
            {
                return "#!/" + coreUrl;
            }
            else
            {
                return context.RequestContext.TranslateVirtualPath("~/" + coreUrl);
            }
        }
示例#16
0
 /// <summary>
 /// Renders the contents inside the control begin and end tags.
 /// </summary>
 protected override void RenderContents(IHtmlWriter writer, RenderContext context)
 {
     var textBinding = GetBinding(TextProperty);
     if (textBinding == null && !string.IsNullOrEmpty(Text))
     {
         // render static value of the text property
         writer.WriteText(Text);
     }
     else
     {
         // render control contents
         RenderChildren(writer, context);
     }
 }
示例#17
0
文件: Button.cs 项目: adamjez/dotvvm
        /// <summary>
        /// Adds all attributes that should be added to the control begin tag.
        /// </summary>
        protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context)
        {
            writer.AddAttribute("type", IsSubmitButton ? "submit" : "button");

            var clickBinding = GetCommandBinding(ClickProperty);
            if (clickBinding != null)
            {
                writer.AddAttribute("onclick", KnockoutHelper.GenerateClientPostBackScript(clickBinding, context, this));
            }

            writer.AddKnockoutDataBind("value", this, TextProperty, () => writer.AddAttribute("value", Text));

            base.AddAttributesToRender(writer, context);
        }
示例#18
0
        protected override void RenderContents(IHtmlWriter writer, RenderContext context)
        {
            if (RenderOnServer)
            {
                if (!string.IsNullOrWhiteSpace(EmptyItemText))
                {
                    writer.RenderBeginTag("option");
                    writer.WriteText(EmptyItemText);
                    writer.RenderEndTag();
                }
            }

            base.RenderContents(writer, context);
        }
示例#19
0
        /// <summary>
        /// Adds all attributes that should be added to the control begin tag.
        /// </summary>
        protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context)
        {
            writer.AddAttribute("href", "#");

            var clickBinding = GetCommandBinding(ClickProperty);
            if (clickBinding != null)
            {
                writer.AddAttribute("onclick", KnockoutHelper.GenerateClientPostBackScript(clickBinding, context, this));
            }

            writer.AddKnockoutDataBind("text", this, TextProperty, () => { });

            base.AddAttributesToRender(writer, context);
        }
示例#20
0
        protected override void RenderContents(IHtmlWriter writer, RenderContext context)
        {
            if (Children.Count == 0) return;

            // render the header
            Children[0].Render(writer, context);

            // render body
            var dataSourceBinding = GetDataSourceBinding();
            if (!RenderOnServer)
            {
                var expression = dataSourceBinding.TranslateToClientScript(this, DataSourceProperty);
                writer.AddKnockoutForeachDataBind(expression);
            }
            writer.RenderBeginTag("tbody");

            // render contents
            if (RenderOnServer)
            {
                // render on server
                var index = 0;
                foreach (var child in Children.Skip(1))
                {
                    context.PathFragments.Push(dataSourceBinding.GetViewModelPathExpression(this, DataSourceProperty) + "[" + index + "]");
                    Children[index].Render(writer, context);
                    context.PathFragments.Pop();
                    index++;
                }
            }
            else
            {
                // render on client
                for (var i = Children.Count - 1; i > 0; i--)
                {
                    Children.RemoveAt(i);
                }

                var placeholder = new DataItemContainer();
                placeholder.SetValue(Internal.IsDataContextBoundaryProperty, true);
                Children.Add(placeholder);
                CreateRow(context.RequestContext, placeholder);

                context.PathFragments.Push(dataSourceBinding.GetViewModelPathExpression(this, DataSourceProperty) + "[$index]");
                placeholder.Render(writer, context);
                context.PathFragments.Pop();
            }

            writer.RenderEndTag();
        }
示例#21
0
        protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context)
        {
            writer.AddKnockoutDataBind("with", this, UploadedFilesProperty, () =>
            {
                throw new Exception("The UploadedFiles property of the FileUpload control must be bound!");   // TODO: Exception handling
            });
            writer.AddAttribute("class", "rw-upload", true);

            var uploadCompletedBinding = GetCommandBinding(UploadCompletedProperty);
            if (uploadCompletedBinding != null)
            {
                writer.AddAttribute("data-upload-completed", KnockoutHelper.GenerateClientPostBackScript(uploadCompletedBinding, context, this, true, null));
            }

            base.AddAttributesToRender(writer, context);
        }
示例#22
0
        public void RenderPage(RedwoodRequestContext context, RedwoodView view)
        {
            // embed resource links
            EmbedResourceLinks(view);

            // prepare the render context
            var renderContext = new RenderContext(context);

            // get the HTML
            using (var textWriter = new StringWriter())
            {
                var htmlWriter = new HtmlWriter(textWriter, context);
                view.Render(htmlWriter, renderContext);
                context.RenderedHtml = textWriter.ToString();
            }
        }
示例#23
0
        private static Dictionary<string, object> ComposeNewRouteParameters(HtmlGenericControl control, RenderContext context, RouteBase route)
        {
            var parameters = new Dictionary<string, object>(route.DefaultValues);
            foreach (var param in context.RequestContext.Parameters)
            {
                parameters[param.Key] = param.Value;
            }
            foreach (var attr in GetRouteParameters(control))
            {
                var parameterName = attr.Key.Substring(RouteParameterPrefix.Length);
                parameters[parameterName] = attr.Value;

                // remove the attribute because we don't want to be rendered
                control.Attributes.Remove(attr.Key);
            }
            return parameters;
        }
示例#24
0
        protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context)
        {
            writer.AddAttribute("id", ID);
            writer.AddAttribute("name", Constants.SpaContentPlaceHolderID);
            writer.AddAttribute(Constants.SpaContentPlaceHolderDataAttributeName, GetSpaContentPlaceHolderUniqueId());

            if (!string.IsNullOrEmpty(DefaultRouteName))
            {
                var route = context.RequestContext.Configuration.RouteTable[DefaultRouteName];
                if (route.ParameterNames.Any())
                {
                    throw new ArgumentException(string.Format("The route {0} specified in SpaContentPlaceHolder DefaultRouteName property cannot contain route parameters!", DefaultRouteName));
                }
                writer.AddAttribute(Constants.SpaContentPlaceHolderDefaultRouteDataAttributeName, route.Url);
            }
            base.AddAttributesToRender(writer, context);
        }
示例#25
0
        /// <summary>
        /// Renders the control into the specified writer.
        /// </summary>
        protected override void RenderControl(IHtmlWriter writer, RenderContext context)
        {
            // render resource links
            var resources = context.ResourceManager.GetResourcesInOrder().Where(r => r.GetRenderPosition() == ResourceRenderPosition.Body);
            foreach (var resource in resources)
            {
                resource.Render(writer);
            }

            // render the serialized viewmodel
            var serializedViewModel = context.RequestContext.GetSerializedViewModel();
            writer.AddAttribute("type", "hidden");
            writer.AddAttribute("id", "__rw_viewmodel_" + context.CurrentPageArea);
            writer.AddAttribute("value", serializedViewModel);
            writer.RenderSelfClosingTag("input");

            // init on load
            writer.RenderBeginTag("script");
            writer.WriteUnencodedText(string.Format("redwood.onDocumentReady(function () {{ redwood.init('{0}', '{1}'); }});", context.CurrentPageArea, Thread.CurrentThread.CurrentUICulture.Name));
            writer.RenderEndTag();
        }
示例#26
0
文件: TextBox.cs 项目: adamjez/dotvvm
        /// <summary>
        /// Adds all attributes that should be added to the control begin tag.
        /// </summary>
        protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context)
        {
            writer.AddKnockoutDataBind("value", this, TextProperty, () =>
            {
                if (Type != TextBoxType.MultiLine)
                {
                    writer.AddAttribute("value", "Text");
                }
            }, UpdateTextAfterKeydown ? "afterkeydown" : null);

            if (Type == TextBoxType.Normal)
            {
                TagName = "input";
                if (!Attributes.ContainsKey("type"))
                {
                    writer.AddAttribute("type", "text");
                }
            }
            else if (Type == TextBoxType.Password)
            {
                writer.AddAttribute("type", "password");
                TagName = "input";
            }
            else if (Type == TextBoxType.MultiLine)
            {
                TagName = "textarea";
            }

            // prepare changed event attribute
            var changedBinding = GetCommandBinding(ChangedProperty);
            if (changedBinding != null)
            {
                writer.AddAttribute("onchange", KnockoutHelper.GenerateClientPostBackScript(changedBinding, context, this, true));
            }

            base.AddAttributesToRender(writer, context);
        }
示例#27
0
        /// <summary>
        /// Renders the children.
        /// </summary>
        protected override void RenderControl(IHtmlWriter writer, RenderContext context)
        {
            // label
            var textBinding = GetBinding(TextProperty);
            var labelRequired = textBinding != null || !string.IsNullOrEmpty(Text) || !HasOnlyWhiteSpaceContent();
            if (labelRequired)
            {
                writer.RenderBeginTag("label");
            }

            // prepare changed event attribute
            var changedBinding = GetCommandBinding(ChangedProperty);
            if (changedBinding != null)
            {
                writer.AddAttribute("onclick", KnockoutHelper.GenerateClientPostBackScript(changedBinding, context, this, true, true));
            }

            // handle enabled attribute
            writer.AddKnockoutDataBind("enable", this, EnabledProperty, () =>
            {
                if (!Enabled)
                {
                    writer.AddAttribute("disabled", "disabled");
                }
            });

            // add ID
            AddControlIdAttribute(writer);

            // render the radio button
            RenderInputTag(writer);

            // render the label
            if (labelRequired)
            {
                if (textBinding != null)
                {
                    writer.AddKnockoutDataBind("text", this, TextProperty, () => { });
                    writer.RenderBeginTag("span");
                    writer.RenderEndTag();
                }
                else if (!string.IsNullOrEmpty(Text))
                {
                    writer.WriteText(Text);
                }
                else if (!HasOnlyWhiteSpaceContent())
                {
                    RenderChildren(writer, context);
                }

                writer.RenderEndTag();
            }
        }
示例#28
0
        /// <summary>
        /// Adds all attributes that should be added to the control begin tag.
        /// </summary>
        protected override void AddAttributesToRender(IHtmlWriter writer, RenderContext context)
        {
            var validatedValueBinding = GetValueBinding(ValidatedValueProperty);
            if (validatedValueBinding != null)
            {
                writer.AddKnockoutDataBind("redwoodValidation", this, ValidatedValueProperty, () => { });

                var options = string.Format("{{'mode':'{0}', 'cssClass':{1}}}", KnockoutHelper.ConvertToCamelCase(Mode.ToString()), KnockoutHelper.MakeStringLiteral(InvalidCssClass));
                writer.AddKnockoutDataBind("redwoodValidationOptions", options);
            }

            base.AddAttributesToRender(writer, context);
        }
示例#29
0
 protected override void RenderEndTag(IHtmlWriter writer, RenderContext context)
 {
     base.RenderEndTag(writer, context);
     writer.RenderEndTag();
 }
示例#30
0
 protected override void RenderBeginTag(IHtmlWriter writer, RenderContext context)
 {
     writer.RenderBeginTag("div");
     base.RenderBeginTag(writer, context);
 }