Nov 16, 2012, 4:27 PM
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
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();
}
}