Why do the mobile controls have to be re-created on every postback?

K

k m

I am writing a test page to test the ability to create dynamic mobile
pages (see my code below). The code as I currently have it seems to
work in Pocket IE.

The code that generates the controls for Form1 is currently in the
Page_Load method. I have three questions:

1. Why does it not work to put that code inside of an if(!IsPostBack)
{} ?

2. Why does it not work to put that code in the Form1_OnActivate method
instead?

3. In the Openwave SDK 6.2.2 emulator, why do I get an error when
clicking on the calendar or the "ok" button? It says "error: malformed
server response"

thank you!

Test.aspx --
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<%@ Page language="c#" Codebehind="Test.aspx.cs" Inherits="Caps.Test"
AutoEventWireup="false" %>

<HEAD>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="C#">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/Mobile/Page">
</HEAD>

<body Xmlns:mobile="http://schemas.microsoft.com/Mobile/WebForm">
<mobile:Form runat="server" ID="Form1"
OnActivate="Form1_OnActivate"></mobile:Form>
<mobile:Form runat="server" id="SecondForm"
OnActivate="SecondForm_OnActivate"></mobile:Form>
</body>

Test.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.HtmlControls;

namespace Caps
{
public class Test : System.Web.UI.MobileControls.MobilePage
{
protected System.Web.UI.MobileControls.Form Form1;
protected System.Web.UI.MobileControls.Form SecondForm;

private void Page_Load(object sender, System.EventArgs e)
{
Form1.Controls.Add(NewLabel("Label1", "Type in something:"));
Form1.Controls.Add(NewTextBox("TypeIn"));

Form1.Controls.Add(NewLabel("Label2", "Choose a date:"));
Form1.Controls.Add(NewCalendar("Calendar"));

Form1.Controls.Add(NewCommand(new
System.EventHandler(this.GoCommand_OnClick), "OK", "Command1"));
}

protected void GoCommand_OnClick(Object sender, System.EventArgs e)
{
ActiveForm = SecondForm;
}

protected void Form1_OnActivate(Object sender, EventArgs e)
{
}

protected void SecondForm_OnActivate(Object sender, EventArgs e)
{
TextBox oTypeIn = (TextBox) FindControl("TypeIn");
Calendar oCalendar = (Calendar) FindControl("Calendar");

SecondForm.Controls.Add(NewLabel("a", "You Selected:"));
SecondForm.Controls.Add(NewLabel("b", "TypeIn: " + oTypeIn.Text));
SecondForm.Controls.Add(NewLabel("c", "Date: " +
oCalendar.SelectedDate.ToString()));
}

protected Command NewCommand(System.EventHandler oOnClick, string
strText, string strID)
{
Command oCommand = new Command();
oCommand.Click += oOnClick;
oCommand.Text = strText;
oCommand.ID = strID;
return oCommand;
}

protected Label NewLabel(string strID, string strText)
{
Label oLabel = new Label();
oLabel.ID = strID;
oLabel.Text = strText;
return oLabel;
}

protected TextBox NewTextBox(string strID)
{
TextBox oTextBox = new TextBox();
oTextBox.ID = strID;
return oTextBox;
}

protected Calendar NewCalendar(string strID)
{
Calendar oCalendar = new Calendar();
oCalendar.ID = strID;
return oCalendar;
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top