This is a migrated thread and some comments may be shown as answers.

Cannot collect data from controls in TemplateColumn on PerformInsert

0 Answers 63 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dmitry
Top achievements
Rank 1
Dmitry asked on 23 Sep 2011, 12:47 PM
Hello,
I build whole grid programmatically from Page_Init and assign DataSource to dynamically built datasource. I can edit data wihout any problems and now I try to insert row. That's what I do:
1. From client side I fire insert command:
 var master = $find(gridID).get_masterTableView();
 master.fireCommand("InitInsert""");

2. New empty row appears and I enter all data and press Save button. On server side I handle ItemCommand event like this:
case PerformInsertCommandName:
                    GridEditableItem newItem = MasterTableView.GetInsertItem();
                    Dictionary<stringobject> newValues = new Dictionary<stringobject>();
                    newItem.ExtractValues(newValues);
                    break;
and newValues always contain empty values. I try to find controls directly like
WebControl ctl = newItem.FindControl<WebControl>(c => c is IZSheetControl);
but control's value is always null anyway. Have I missed anything?
Below is example of my control which I place in TemplateColumn
public class ZTextBox : TextBoxIScriptControlIZSheetControl
    {
        private ScriptManager sm;
 
        public ZTextBox(ZSheetItem item)
        {
            Item = item;
        }
 
        #region IZSheetControl
        
 
        public ZSheetItem Item { getset; }
        public object Value
        {
            get { return Text; }
            set { Text = value == null ? string.Empty : value.ToString(); }
        }
 
        public int MinWidth
        {
            get { return 120; }
        }
 
        #endregion
 
        #region IScriptControl
 
        IEnumerable<ScriptReferenceIScriptControl.GetScriptReferences()
        {
            ScriptReference reference = new ScriptReference
                                            {
                                                Assembly = "UpeWeb.ASPNET.UI",
                                                Name = "UpeWeb.ASPNET.UI.Scripts.ZTextBox.js",
#if DEBUG
                                                ScriptMode = ScriptMode.Debug,
#else
                                                ScriptMode = ScriptMode.Release,
#endif
                                            };
            yield return reference;
        }
 
        IEnumerable<ScriptDescriptorIScriptControl.GetScriptDescriptors()
        {
            var control = new ScriptControlDescriptor("UpeWeb.ASPNET.UI.Controls.ZTextBox", ClientID);
            control.AddProperty("text", Text);
            yield return control;
        }
 
        #endregion
 
        protected override void OnPreRender(EventArgs e)
        {
            if (!DesignMode)
            {
                sm = ScriptManager.GetCurrent(Page);
 
                if (sm == null)
                    throw new HttpException("A ScriptManager control must exist on the current page.");
 
                sm.RegisterScriptControl(this);
            }
 
            base.OnPreRender(e);
        }
 
        protected override void Render(HtmlTextWriter writer)
        {
            if (!DesignMode)
                sm.RegisterScriptDescriptors(this);
 
            base.Render(writer);
        }
    }

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Dmitry
Top achievements
Rank 1
Share this question
or