[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.mobile

Re: Button.Command event handler not working?

airerich

1/6/2005 7:31:00 PM

Did you ever get an answer to your question regarding this?
I am having the same problem and would ilke to know how you solved
this.
Thanks a ton.


Chee Pin wrote:
> I have a Table control in the header section of
> stylesheet template of a mobile page. During page load, I
> insert a row of TableCells into the table. In one of the
> table cell, I have inserted a Button into the cell and
> also added a eventhandler to it to consume Button.Command
> event. But whenever the button is clicked, my code in the
> eventhandler is never called.
>
> I am wondering if I am doing something wrong in this case.
>
> Attached below are my code.
> 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;
> using Factory.Mobile.Cache;
> using ChartDirector;
>
> namespace MobileFactoryView
> {
> /// <summary>
> /// Summary description for EqpViewForm.
> /// </summary>
> public class EqpViewForm : System.Web.UI.MobileControls.MobilePage
> {
> protected System.Web.UI.MobileControls.StyleSheet
ToolModuleStyleSheet;
> protected IntelMobileControls.TimerFormCS ToolModuleView;
> protected System.Web.UI.MobileControls.DeviceSpecific devPIETool;
> private System.Web.UI.WebControls.Table webTable = null;
> protected System.Web.UI.MobileControls.Image ChartImg;
> private System.Web.UI.MobileControls.Label Header = null;
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> if (!IsPostBack)
> {
> Initialize_ModuleView();
> }
> }
>
> private void Initialize_ModuleView()
> {
> // Iterate through the controls in the form.
> foreach(Control c in ToolModuleView.Controls)
> {
> // Is the control is templated (we know our link is the only
one)?
> if(c.GetType().ToString() ==
> "System.Web.UI.MobileControls.TemplateContainer")
> {
> foreach(Control d in c.Controls)
> {
> if (d.ID == "HeaderLabel")
> Header = (System.Web.UI.MobileControls.Label)d;
> else if (d.ID == "tblModuleView")
> webTable = (System.Web.UI.WebControls.Table)d;
> }
>
> // Get hold of the data for the table
> string selectedModule = (string)Session["Selected_EqpArea"];
> ArrayList modules = (ArrayList)Session["EqpArea_Data"];
>
> // Set the header correctly
> if (Header != null)
> Header.Text = "Equipment Module View - " + selectedModule;
> else
> Response.Write("damned");
> if (webTable != null)
> Populate_Table(modules);
> }
> }
> }
>
> private void Update_ModuleView(ArrayList modules)
> {
> // Clear the table except for the header row :)
> ArrayList indexs = new ArrayList();
> IEnumerator itr = webTable.Rows.GetEnumerator();
> itr.Reset();
> itr.MoveNext();
> while(itr.MoveNext())
> {
> TableRow row = (TableRow)itr.Current;
> int index = webTable.Rows.GetRowIndex(row);
> indexs.Add(index);
> }
> foreach (object obj in indexs)
> {
> int i = (int)obj;
> webTable.Rows.RemoveAt(i);
> }
> Populate_Table(modules);
> }
>
> private void Populate_Table(ArrayList modules)
> {
> // Populate the table accordingly
> TableRowCollection rows = webTable.Rows;
> IEnumerator itr = rows.GetEnumerator();
> itr.Reset();
> itr.MoveNext();
> TableRow headerRow = (TableRow)itr.Current;
> int columns = headerRow.Cells.Count;
> foreach (EquipmentModule eqpmodules in modules)
> {
> TableRow newRow = new TableRow();
>
> // Insert cells into the row, first one is EntityId, followed by
> // State, AlarmCount and Detail as button
> TableCell entityCell = new TableCell();
> entityCell.Controls.Add(new LiteralControl(eqpmodules.EntityId));
> newRow.Cells.Add(entityCell);
> TableCell stateCell = new TableCell();
> stateCell.Controls.Add(new LiteralControl(eqpmodules.State));
> newRow.Cells.Add(stateCell);
> TableCell detailCell = new TableCell();
> Button detailCmd = new Button();
> detailCmd.Text = "Detailed";
> detailCmd.ID = eqpmodules.EntityId;
> detailCmd.CommandName = "Select";
> detailCmd.CommandArgument = eqpmodules.EntityId;
> detailCmd.Command += new CommandEventHandler(
> this.OnDetailInfoRequested);
> detailCell.Controls.Add(detailCmd);
> newRow.Cells.Add(detailCell);
> webTable.Rows.Add(newRow);
> }
> webTable.DataBind();
> }
>
> private void OnDetailInfoRequested(object sender, CommandEventArgs
e)
> {
> if (e.CommandName == "Select")
> {
> Session["Selected_EqpModule"] = e.CommandArgument;
> ArrayList modules = (ArrayList)Session["EqpArea_Data"];
> IEnumerator itr = modules.GetEnumerator();
> itr.Reset();
> while(itr.MoveNext())
> {
> Equipment data = (Equipment)itr.Current;
> if (data.EntityId == e.CommandArgument)
> {
> Session["EqpModule_data"] = data;
> break;
> }
> }
> RedirectToMobilePage("ToolForm.aspx");
> }
> }
> private void UpdateChartView(EquipmentModule module)
> {
> ChartDirector.API cd = (API)new APIClass();
>
> // Set the size of the image with background color
> int size = 180;
> object osize = (object)size;
> object bcolor = (object)Color.LightCyan.ToArgb();
> object edgecolor = (object)Color.White.ToArgb();
> ChartDirector.PieChart pc = (PieChart)cd.PieChart(ref osize, ref
osize,
> ref bcolor, ref edgecolor);
>
> // Set the title
> string title = "Module Utilization Chart";
> object otitle = (object)title;
> object other = null;
> pc.addTitle(ref otitle, ref other, ref other, ref other, ref
other,
> ref other);
>
> // Set data and make chart
> string filename =
"C:\\Inetpub\\wwwroot\\MobileFactoryView\\Images\\1.jpg";
> object ofile = (object)filename;
>
> // Fill in the data
> ArrayList data = new ArrayList();
> ArrayList label = new ArrayList();
> foreach(StateDuration sd in module.StateDetail.StateDurations)
> {
> data.Add(sd.Duration);
> label.Add(sd.State);
> }
>
> object objData = (object)data.ToArray(typeof(int));
> object objLabels = (object)label.ToArray(typeof(string));
> pc.setData(ref objData, ref objLabels);
> int pos = 90;
> object objPos = (object)pos;
> object objRadius = (object)(size - 130);
> pc.setPieSize(ref objPos, ref objPos, ref objRadius);
> pc.makeChart(ref ofile);
> }
> #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.ToolModuleView.Timer += new
System.EventHandler(this.ToolModuleView_OnTimer);
> this.ToolModuleView.Activate += new
System.EventHandler(this.ToolModuleView_Activate);
> this.Load += new System.EventHandler(this.Page_Load);
>
> }
> #endregion
>
> private void ToolModuleView_Activate(object sender,
System.EventArgs e)
> {
>
> }
>
> private void ToolModuleView_OnTimer(object sender, System.EventArgs
e)
> {
> // Iterate through the controls in the form.
> foreach(Control c in ToolModuleView.Controls)
> {
> // Is the control is templated (we know our link is the only
one)?
> if(c.GetType().ToString() ==
> "System.Web.UI.MobileControls.TemplateContainer")
> {
> foreach(Control d in c.Controls)
> {
> if (d.ID == "HeaderLabel")
> Header = (System.Web.UI.MobileControls.Label)d;
> else if (d.ID == "tblModuleView")
> webTable = (System.Web.UI.WebControls.Table)d;
> }
>
> // Get hold of the data for the table
> string selectedModule = (string)Session["Selected_EqpModule"];
> ArrayList modules = (ArrayList)Session["EqpModule_Data"];
>
> // Set the header correctly
> if (Header != null)
> Header.Text = "Equipment Module View - " + selectedModule;
> else
> Response.Write("damned");
> if (webTable != null)
> {
> CacheManagerProxy cacheMgr = new CacheManagerProxy();
> EquipmentData data = cacheMgr.GetModuleStatus(
> (string)Session["Selected_EqpModule"]);
> Update_ModuleView(data.Modules);
> }
> }
> }
> }
> }
> }