Creating a Form Using XmlPropertyObject
Prerequisites
Step by Step – Using the XmlPropertyObject
Summary
Shows how to create a custom save and retrieve form using the XmlPropertyObject
Video
Reference Materials
ASampleClass.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebFormsApplication1.App_Code;
namespace WebFormsApplication1.App_Code
{
public class ASampleClass : XmlPropertyObject
{
public string aProperty1 { get; set; }
public string aProperty2 { get; set; }
public ASampleClass() { }
public ASampleClass(int ID) : base(ID) { }
}
}
ASamplePage.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ASamplePage.aspx.cs" Inherits="WebFormsApplication1.Pages.ASamplePage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<br />
<asp:Label ID="Label1" runat="server" Text="Label">A Property 1</asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:Label ID="Label2" runat="server" Text="Label">A Property 2</asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br /><br />
<asp:Button ID="ButtonSave" runat="server" Text="Save" OnClick="ButtonSave_Click" /><asp:Button ID="ButtonUpdate" runat="server" Text="Update" OnClick="ButtonUpdate_Click" />
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
</asp:Content>
ASamplePage.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebFormsApplication1.App_Code;
namespace WebFormsApplication1.Pages
{
public partial class ASamplePage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["ObjectID"] != null)
{
int id = Convert.ToInt32(Request.QueryString["ObjectID"]);
ASampleClass ac = new ASampleClass(id);
TextBox1.Text = ac.aProperty1;
TextBox2.Text = ac.aProperty2;
ButtonSave.Visible = false;
ButtonUpdate.Visible = true;
}
else
{
ButtonSave.Visible = true;
ButtonUpdate.Visible = false;
}
}
}
protected void ButtonSave_Click(object sender, EventArgs e)
{
ASampleClass ac = new ASampleClass();
ac.aProperty1 = TextBox1.Text;
ac.aProperty2 = TextBox2.Text;
int v = ac.Insert();
Label3.Text = Convert.ToString(v) + " Inserted";
}
protected void ButtonUpdate_Click(object sender, EventArgs e)
{
int id = Convert.ToInt32(Request.QueryString["ObjectID"]);
ASampleClass ac = new ASampleClass(id);
ac.aProperty1 = TextBox1.Text;
ac.aProperty2 = TextBox2.Text;
ac.Update();
Label3.Text = Convert.ToString(id) + " Updated";
}
}
}