Ajax Form Example

Currently, the Form control from nxAjax library is in testing phase

Open Quick Example and Add a new WebForm named Default2.aspx:

<system.web>
<%@ Page Language="C#"  EnableEventValidation="False" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
    <title>Don't use it, it does not works... :(</title>
</head>
<body>
    <ajax:Form runat="server" ID="formu">
        <div>
            <ajax:Button ID="btnOne" Value="One" runat="server" OnServerClick="btnOne_ServerClick"></ajax:Button>
            <ajax:Button ID="btnTwo" Value="Two" runat="server"  OnServerClick="btnTwo_ServerClick"></ajax:Button>
            <ajax:TextBox ID="txtOne" runat="server" Value="One"></ajax:TextBox>
            <ajax:Submit ID="submitOne" runat="server" OnServerClick="submitOne_ServerClick"></ajax:Submit>
        </div>
    </ajax:Form>
   <form id="form1" runat="server">
        <div>
            <asp:Button ID="btnAsp" Text="Asp" runat="server" OnClick="btnAsp_Click" />
            <asp:TextBox ID="txtAsp" Text="" AutoPostBack="True" runat="server" OnTextChanged="btnAsp_Click" />
        </div>
    </form>
</body>
</html>
</system.web>

In order to it works properly you should modify the WebForm Properties:
EnableViewState = true;
EnableEventValidation = false;
ViewStateEncryptionMode = System.Web.UI.ViewStateEncryptionMode.Never;
EnableViewStateMac = false;

And add the event management code in the code behind. The final result should be something like:
using System;
using System.Collections.Generic;
using System.Linq;

using Framework.Ajax.UI;
using Framework.Ajax.UI.Controls;

public partial class Default2 : System.Web.UI.Page
{
    public Default2() : base()
    {
        this.EnableViewState = true;
        this.EnableEventValidation = false;
        this.ViewStateEncryptionMode = System.Web.UI.ViewStateEncryptionMode.Never;
        this.EnableViewStateMac = false;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            
        }
    }
    protected void btnOne_ServerClick(AjaxControl sender, string value)
    {
        btnOne.AjaxController.DocumentAlert("Hi!! " + value);
        txtOne.Value = "Three";
    }
    protected void submitOne_ServerClick(AjaxControl sender, string value)
    {
        txtOne.Value = "One";
    }
    protected void btnTwo_ServerClick(AjaxControl sender, string value)
    {
        btnOne.AjaxController.DocumentAlert("Hi!! " + value);
        txtOne.Value = "Two";
    }
    protected void btnAsp_Click(object sender, EventArgs e)
    {
        txtOne.AjaxController.DocumentAlert("Hi! " + btnAsp.Text);
        txtOne.Value = "Three";
    }
}

Do not forget comment your experiences ;)

Last edited Feb 12, 2010 at 3:26 PM by fescolar, version 6

Comments

No comments yet.