Exception loading record for form panel

  1. #1

    Exception loading record for form panel

    Hi, i m trying to bind FormPanel to My object TestPerson.
    I don't know whitch is the best way to do it !!!
    So : I have created a store with only one element TestPerson an i want to call loadRecord on my formPanel
    like this emeple : https://examples1.ext.net/#/Form/Mis...ous/Form_View/

    but i had this exception : Microsoft JScript runtime error: 'UserForm' is undefined

    Thank you for help



    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="FormPanelBindedToStore.aspx.cs" Inherits="FormPanel_FormPanelBindedToStore" %>
    
    
    <%@ Import Namespace="System.Collections.Generic"%>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
       
    </script>
        
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Grid with AutoSave - Ext.NET Examples</title>
        <link href="../../../../resources/css/examples.css" rel="stylesheet" type="text/css" />    
        <script type="text/javascript">
            var updateRecord = function (form) {
                if (form.record == null) {
                    return;
                }
    
                if (!form.getForm().isValid()) {
                    Ext.net.Notification.show({
                        iconCls: "icon-exclamation",
                        html: "Form is invalid",
                        title: "Error"
                    });
                    return false;
                }
    
                form.getForm().updateRecord(form.record);
            };       
        </script>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            
            <h1>Grid with AutoSave</h1>
            
            <p>An Error has been simulated on the server-side: Attempting to update a record having ODD-numbered id will generate this errror. This error can be handled by listening to the "exception" event upon your Store.</p>
            
            <ext:Store 
                ID="Store1" 
                runat="server" 
                AutoSave="true" 
                ShowWarningOnFailure="false"
                OnBeforeRecordUpdated="handelRecorUpdate"
                SkipIdForNewRecords="false"
                RefreshAfterSaving="None">
                <Reader>
                    <ext:JsonReader IDProperty="Id">
                        <Fields>
                            <ext:RecordField Name="Id" />
                            <ext:RecordField Name="Email" AllowBlank="false" />
                            <ext:RecordField Name="First" AllowBlank="false" />
                            <ext:RecordField Name="Last" AllowBlank="false" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>            
                <Listeners>
                    <%--#{UserForm}.getForm().loadRecord(record);#{UserForm}.record = record;--%>
                    <DataChanged Handler="var record = this.getAt(0) || {};#{UserForm}.getForm().loadRecord(record);#{UserForm}.clearInvalid();" />
                    <%--<afterrender Handler="var record = this.getAt(0) || {};#{UserForm}.getForm().loadRecord(record);#{UserForm}.clearInvalid();" />--%>
                    <BeforeSave Handler="var valid = true; this.each(function(r){if(r.dirty && !r.isValid()){valid=false;}}); return valid;" />
                    
                </Listeners>
            </ext:Store>
            
            <ext:Hidden ID="UseConfirmation" runat="server" Text="false" />
            
            <ext:FormPanel 
                ID="UserForm" 
                runat="server"
                Icon="User"
                Frame="true"
                LabelAlign="Right"
                Title="User -- All fields are required"
                Width="500">
                <Items>
                    <ext:TextField ID="TextField1" runat="server"
                        FieldLabel="Email"
                        DataIndex="Email"
                        AllowBlank="false"
                        Vtype="email"
                        AnchorHorizontal="100%"
                        />
                    
                    <ext:TextField ID="TextField2" runat="server"
                        FieldLabel="First"
                        DataIndex="First"
                        AllowBlank="false"
                        AnchorHorizontal="100%"
                        />
                    
                    <ext:TextField ID="TextField3" runat="server"
                        FieldLabel="Last"
                        DataIndex="Last"
                        AllowBlank="false"
                        AnchorHorizontal="100%"
                        />
                </Items>
                
                <Buttons>
                    <ext:Button 
                        runat="server"
                        Text="Save"
                        Icon="Disk">
                        <Listeners>
                            <Click Handler="updateRecord(#{UserForm});" />
                        </Listeners>
                    </ext:Button>
                    
                    <ext:Button 
                        runat="server"
                        Text="Reset">
                        <Listeners>
                            <Click Handler="#{UserForm}.getForm().reset();" />
                        </Listeners>
                    </ext:Button>
                </Buttons>
            </ext:FormPanel>               
        </form>
    </body>
    </html>
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Ext.Net;
    
    public partial class FormPanel_FormPanelBindedToStore : System.Web.UI.Page
    {
        //#{CategoriesFormPanel}.getForm().setValues({Id:'6',CategoryName:'Test',HeirarchyLevel:'2',ParentTraumaCategoryId:'2'});
        protected void Page_Load(object sender, EventArgs e)
        {
            //UserForm.Element = new Element(
            bool useConfirmation;
    
            if (bool.TryParse(UseConfirmation.Text, out useConfirmation))
            {
                this.Store1.SuspendScripting();
                this.Store1.UseIdConfirmation = useConfirmation;
                this.Store1.ResumeScripting();
            }
    
            this.BindData();
        }
    
        public class TestPerson
        {
            public int Id
            {
                get;
                set;
            }
    
            public string Email
            {
                get;
                set;
            }
    
            public string First
            {
                get;
                set;
            }
    
            public string Last
            {
                get;
                set;
            }
        }
    
        //----------------Page------------------------
      
        private List<TestPerson> CurrentData
        {
            get
            {
                var persons = this.Session["TestPersons"];
    
                if (persons == null)
                {
                    persons = new List<TestPerson>
                       {
                           new TestPerson{Id=1, Email="fred@flintstone.com", First="Fred", Last="Flintstone"},                   
                       };
                    this.Session["TestPersons"] = persons;
                }
    
                return (List<TestPerson>)persons;
            }
        }
    
        private void BindData()
        {
            if (!X.IsAjaxRequest)
            {
                this.Store1.DataSource = this.CurrentData;
                this.Store1.DataBind();            
            }
        }
    
        protected void handelRecorUpdate(object sender, BeforeRecordUpdatedEventArgs e)
        {
            TestPerson modifiedrecord = e.Object<TestPerson>();
          
            //SaveOndataBase
    
            e.Confirmation.ConfirmRecord();
    
        }
        
    }
  2. #2
    Hi Smaoui,

    This is a strange one, I haven't seen this before but basically, I got it to work by defining the Form before the Store in my markup. I made a few other changes as well, you may need them:

    Codebehind:

    protected void Page_Load(object sender, EventArgs e)
    {            
        bool useConfirmation;
    
    
        if (bool.TryParse(UseConfirmation.Text, out useConfirmation) && useConfirmation)
        {
            this.Store1.SuspendScripting();
            this.Store1.UseIdConfirmation = useConfirmation;
            this.Store1.ResumeScripting();
        }
    
    
        this.BindData();
    }
    bool.TryParse will return true if the parse is successful, regardless of whether the value of UseConfirmation.Text is true or false. So, you need to add the second clause to your if statement.

    Markup:
    <form id="form1" runat="server">
        <ext:ResourceManager runat="server" ID="ResourceManager1" />
            
        <ext:Hidden ID="UseConfirmation" runat="server" Text="false" />
             
        <ext:FormPanel ID="UserForm" runat="server" Icon="User" Frame="true"  LabelAlign="Right" Title="User -- All fields are required" Width="500" AutoHeight="true">
            <Defaults>
                <ext:Parameter Name="allowBlank" Value="false" Mode="Raw" />
                <ext:Parameter Name="anchor" Value="100%" />
            </Defaults>
            <Items>
                <ext:TextField ID="TextField1" runat="server" FieldLabel="Email" DataIndex="Email" Vtype="email" />
                <ext:TextField ID="TextField2" runat="server" FieldLabel="First" DataIndex="First" />
                <ext:TextField ID="TextField3" runat="server" FieldLabel="Last" DataIndex="Last" />
            </Items>
                 
            <Buttons>
                <ext:Button ID="Button1" runat="server" Text="Save" Icon="Disk">
                    <Listeners>
                        <Click Handler="updateRecord(#{UserForm});" />
                    </Listeners>
                </ext:Button>
                     
                <ext:Button ID="Button2" runat="server" Text="Reset">
                    <Listeners>
                        <Click Handler="#{UserForm}.getForm().reset();" />
                    </Listeners>
                </ext:Button>
            </Buttons>
        </ext:FormPanel>
            
        <ext:Store ID="Store1" runat="server" AutoSave="true" 
            ShowWarningOnFailure="false" 
            OnBeforeRecordUpdated="handelRecorUpdate"
            SkipIdForNewRecords="false"
            RefreshAfterSaving="None">
            <Reader>
                <ext:JsonReader IDProperty="Id">
                    <Fields>
                        <ext:RecordField Name="Id" />
                        <ext:RecordField Name="Email" AllowBlank="false" />
                        <ext:RecordField Name="First" AllowBlank="false" />
                        <ext:RecordField Name="Last" AllowBlank="false" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
            <Listeners>                
                <DataChanged Handler="var record = this.getAt(0) || {}; #{UserForm}.getForm().loadRecord(record); #{UserForm}.clearInvalid();" />
                <BeforeSave Handler="var valid = true; this.each(function(r) { if(r.dirty && !r.isValid()) { valid=false; } }); return valid;" />
            </Listeners>
        </ext:Store>           
    </form>
    Using this, I was able to get the form up and running and bound to the first record. There are more problems - your updateRecord script method does not work - but I leave those to you to follow up.
  3. #3
    Last edited by smaoui; Nov 19, 2012 at 9:31 AM.

Similar Threads

  1. Replies: 1
    Last Post: Sep 13, 2012, 7:52 AM
  2. [CLOSED] Field and FieldContainer layout exception in form
    By cleve in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Aug 13, 2012, 2:04 PM
  3. Replies: 5
    Last Post: May 11, 2012, 4:56 PM
  4. Insert Record Form Panel
    By lindgrenm in forum 1.x Help
    Replies: 17
    Last Post: May 17, 2011, 7:01 PM
  5. [CLOSED] Add record to store via form
    By craig2005 in forum 1.x Legacy Premium Help
    Replies: 20
    Last Post: May 17, 2011, 6:45 PM

Posting Permissions