protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            // This ensures that the template control is properly initialized
            ScriptTemplateControl.GetScriptTemplateControl(this);
        }
        private void ControlOnDataBinding(object sender, EventArgs e)
        {
            ScriptTemplateControl scriptTemplateControl = ScriptTemplateControl.GetScriptTemplateControl(this);


            object evaluatedCode = scriptTemplateControl.EvaluateDataBindingExpression(
                this, Code.Trim(), Line);

            // Don't perform the assignment if we got back null/DBNull
            if (evaluatedCode != null && evaluatedCode != DBNull.Value)
            {
                if (_propInfo != null)
                {
                    // Convert the value to a string if needed
                    // TODO: more generic type conversion logic?
                    if (_propInfo.PropertyType == typeof(string) && !(evaluatedCode is string))
                    {
                        evaluatedCode = evaluatedCode.ToString();
                    }

                    _propInfo.SetValue(sender, evaluatedCode, null);
                }
                else
                {
                    _attributeAccessor.SetAttribute(AttributeName, evaluatedCode.ToString());
                }
            }
        }
Beispiel #3
0
        protected override void Render(HtmlTextWriter writer)
        {
            ScriptTemplateControl scriptTemplateControl = ScriptTemplateControl.GetScriptTemplateControl(this);
            object result = scriptTemplateControl.EvaluateExpression(Code.Trim(), Line);

            writer.Write(System.Convert.ToString(result));
        }
Beispiel #4
0
        protected override void OnDataBinding(EventArgs e)
        {
            ScriptTemplateControl scriptTemplateControl = ScriptTemplateControl.GetScriptTemplateControl(this);
            object result = scriptTemplateControl.EvaluateDataBindingExpression(
                this, Code.Trim(), Line);

            Text = System.Convert.ToString(result);
        }
Beispiel #5
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            Control targetControl = FindControl(_targetId);
            ScriptTemplateControl scriptTemplateControl = ScriptTemplateControl.GetScriptTemplateControl(this);

            scriptTemplateControl.HookupControlEvent(targetControl, _eventName, _handlerName, Line);
        }
        private void RenderMethod(HtmlTextWriter writer, Control container)
        {
            ScriptTemplateControl scriptTemplateControl = ScriptTemplateControl.GetScriptTemplateControl(container);

            // Get the compiled code for the render method logic
            CompiledCode compiledCode = scriptTemplateControl.GetSnippetRenderCode(container.UniqueID, this);

            // Execute it in our module
            EngineHelper.ExecuteCompiledCode(compiledCode, scriptTemplateControl.ScriptModule);

            // We should always find our render function in the module
            // REVIEW: we shouldn't have to do this, and should instead work with a lambda like mechanism (bug 218654)
            object f = scriptTemplateControl.ScriptModule.GetVariable(RenderMethodName);

            Debug.Assert(f != null);

            // Call the render method
            DynamicFunction renderFunction = new DynamicFunction(f);

            EngineHelper.CallMethod(scriptTemplateControl.ScriptEngine, renderFunction, null /*defaultVirtualPath*/,
                                    new SnippetRenderHelper(writer, container.Controls));
        }