Mega Code Archive

 
Categories / ASP.Net Tutorial / Mobile
 

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.ComponentModel; 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;     } }