ASP.NET Tutorial/Mobile/Form
Mobile:Form
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="VB" %>
<%@ Register TagPrefix="Mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
<Mobile:Form BackColor="#ccddcc" runat="server">
<Mobile:Label runat="server" Text="Hello World!"/>
</Mobile:Form>
Post to Mobile:form
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="VB" %>
<%@ Register TagPrefix="Mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
<script runat="server">
sub btnAction(Sender as Object, e as EventArgs)
lblMessage.Text = "Transaction:"
lblNumber.Text = tbNumber.Text
lblAmount.Text = tbAmount.Text
ActiveForm = frmThanks
end sub
</script>
<Mobile:Form runat="server">
<Mobile:Label runat="server" StyleReference="title"
Text="Pay Bill" />
<Mobile:Label runat="server" Text="CC #" />
<Mobile:TextBox runat="server" id="tbNumber" />
<Mobile:Label runat="server" Text="Amount $" />
<Mobile:TextBox runat="server" id="tbAmount" />
<Mobile:Command runat="server" id="btSubmit"
OnClick="btnAction"
Text="Pay Bill!" />
</Mobile:Form>
<Mobile:Form runat="server" id="frmThanks">
<Mobile:Label runat="server" id="lblMessage" />
<Mobile:Label runat="server" id="lblNumber" />
<Mobile:Label runat="server" id="lblAmount" />
</Mobile:Form>
Set ActiveForm
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="C#" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
<script runat="server">
void Command1_Click(Object sender, EventArgs e) {
ActiveForm = Form1;
}
void Command2_Click(Object sender, EventArgs e) {
ActiveForm = Form2;
}
</script>
<mobile:Form id="Form1" runat="server">
<mobile:Label id="Label1" runat="server">This is Form1</mobile:Label>
<mobile:Link id="Link1" runat="server" NavigateUrl="#Form2">Go To Form2</mobile:Link>
<mobile:Link id="Link2" runat="server" NavigateUrl="#Form3">Go To Form3</mobile:Link>
</mobile:Form>
<mobile:Form id="Form2" runat="server">
<mobile:Label id="Label2" runat="server">This is Form2</mobile:Label>
<mobile:Link id="Link3" runat="server" NavigateUrl="#Form1">Go To Form1</mobile:Link>
<mobile:Link id="Link4" runat="server" NavigateUrl="#Form3">Go To Form3</mobile:Link>
</mobile:Form>
<mobile:Form id="Form3" runat="server">
<mobile:Label id="Label3" runat="server">This is Form3</mobile:Label>
<mobile:Command id="Command1" onclick="Command1_Click" runat="server">Go To Form1</mobile:Command>
<mobile:Command id="Command2" onclick="Command2_Click" runat="server">Go To Form2</mobile:Command>
</mobile:Form>
Submit a form
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Validate" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<mobile:Form runat="server" id="Main">
<mobile:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Must indicate a skill!"
ControlToValidate="skills">
</mobile:RequiredFieldValidator>
<b>Indicate your skills</b><br />
<mobile:SelectionList runat="server" id="skills" SelectType="checkbox" />
<mobile:Command ID="Command1" runat="server" OnClick="Submit" Text="Send" />
</mobile:Form>
<mobile:Form runat="server" id="ResultsForm">
<b>Recognized skills</b>
<mobile:Label runat="server" id="Results" />
</mobile:Form>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Collections;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Mobile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.MobileControls;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public partial class Validate : System.Web.UI.MobileControls.MobilePage
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ArrayList values = new ArrayList();
values.Add("ASP.NET");
values.Add("ADO.NET");
values.Add("XML");
values.Add("Windows Forms");
values.Add("SQL Server");
skills.DataSource = values;
skills.DataBind();
}
}
protected void Submit(object sender, EventArgs e)
{
if (!Page.IsValid)
return;
string buf = "";
foreach (MobileListItem item in skills.Items)
buf += (item.Selected ? item.Text + ", " : "");
buf = buf.TrimEnd();
if (buf.EndsWith(","))
buf = buf.TrimEnd(",");
Results.Text = buf;
ActiveForm = ResultsForm;
}
}