473,761 Members | 4,511 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Events not firing


Hi,

I am adding controls dynamically in a WebForm, but none of these controls' events fire. Here is the class code I am using. I have tried so many things, but nothing works :-(

namespace WebApplication1

{

using System;

using System.Data;

using System.Collecti ons;

using System.Drawing;

using System.Web;

using System.Web.UI;

using System.Web.UI.W ebControls;

using System.Web.UI.H tmlControls;

using System.Componen tModel;

/// <summary>

/// Summary description for WebUserControl1 .

/// </summary>

public class Tracking : System.Web.UI.W ebControls.WebC ontrol

{

private ArrayList arr = new ArrayList();

private System.Web.UI.W ebControls.Tabl e m_Table = new Table();

private System.Web.UI.W ebControls.Butt on btn = new Button();

//private System.Web.UI.W ebControls.Labe l lbl = new Label();

//private System.Web.UI.W ebControls.Imag e img = new System.Web.UI.W ebControls.Imag e();

//private System.Web.UI.W ebControls.Drop DownList lst = new DropDownList();

public void buildTable(Tabl eTracking trk)

{

//m_Table.BorderS tyle = BorderStyle.Sol id;

//m_Table.BorderW idth = Unit.Pixel(2);

//m_Table.BorderC olor = Color.DarkBlue;

System.Web.UI.W ebControls.Tabl eRow row = new TableRow();

System.Web.UI.W ebControls.Tabl eCell cell = new TableCell();

System.Web.UI.W ebControls.Imag e img = new System.Web.UI.W ebControls.Imag e();

if (trk.Editable== true)

{

//btn.Text = "<font face=Verdana size=1>" + "Edit Me";

btn.Text = "Edit";

img.ImageUrl = "Images/img_sec/edit_pencil.gif ";

cell.Height = 5;

//cell.Horizontal Align = HorizontalAlign .Right;

cell.Width = m_Table.Width;

cell.Controls.A dd(img);

cell.Controls.A dd(new LiteralControl( "&nbsp;"));

//cell.Controls.A dd(new LiteralControl( "<font face=Verdana size=1>"));

cell.Controls.A dd(btn);
row.Cells.Add(c ell);

m_Table.Rows.Ad d(row);

}

else

{

btn.Visible = false;

img.Visible = false;

}

m_Table.Width = trk.Width;

m_Table.Height = trk.Height;

}

public void buildItem(Array List items)

{

System.Web.UI.W ebControls.Tabl eRow row = new TableRow();

System.Web.UI.W ebControls.Tabl eCell cell = null;
//cell.BorderStyl e = BorderStyle.Sol id;

//cell.BorderWidt h = Unit.Pixel(1);

//cell.BorderColo r = Color.DarkBlue;

int currentRow = 0;

int previousRow = 0;

foreach (Item i in items)

{

currentRow = i.Row;

if (currentRow != previousRow && previousRow != 0)

{

m_Table.Rows.Ad d(row);

row = new TableRow();

}

cell = new TableCell();

cell.Horizontal Align = HorizontalAlign .Center;

cell.Width = i.Width;

//cell.Height = Convert.ToStrin g(i.Height);

if (i.Type == "Label")

{

System.Web.UI.W ebControls.Labe l lbl = new Label();

cell.Controls.A dd(new LiteralControl( "<font style='FONT-WEIGHT: bold' face=Verdana size=1>"));

lbl.Text = (string)i.Conte nt[0];

cell.Controls.A dd(lbl);

}

else if (i.Type == "Image")

{

System.Web.UI.W ebControls.Imag e img = new System.Web.UI.W ebControls.Imag e();

img.ImageUrl = (string)i.Conte nt[0];

cell.Controls.A dd(img);

}

else if (i.Type == "DropDownLi st")

{

System.Web.UI.W ebControls.Drop DownList lst = new DropDownList();

arr.Add(lst);

for (int n=0; n<i.Content.Cou nt; n++)

{

lst.Items.Add(( string)i.Conten t[n]);

}

lst.Visible = false;

cell.Controls.A dd(lst);

lst.SelectedInd exChanged+=new EventHandler(ls t_SelectedIndex Changed);

}

row.Cells.Add(c ell);

previousRow = i.Row;

}

m_Table.Rows.Ad d(row);

}

protected override void Render(HtmlText Writer writer)

{

Controls.Clear( );

Controls.Add(m_ Table);

base.Render (writer);

}

private void Page_Load(objec t sender, System.EventArg s e)

{

if (Page.IsPostBac k)

{

foreach(DropDow nList lst in arr)

{

lst.Visible = true;

}

btn.Text = "Save";

}

}
#region Web Form Designer generated code

override protected void OnInit(EventArg s e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeCompo nent();

base.OnInit(e);

}
/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeCompo nent()

{

this.Load += new System.EventHan dler(this.Page_ Load);

}

#endregion

private void lst_SelectedInd exChanged(objec t sender, EventArgs e)

{

Console.WriteLi ne("OK");

}

}

}
This is how the control is set up in the Web Form:
<WEBAPPLICATION 1:TRACKING id=trck1 runat=server></WEBAPPLICATION1 :TRACKING>

Any idea on what could be wrong?

Thanks.
Mike

Nov 18 '05 #1
3 2301
I may be wrong, but suspect that you actually have one event firing - Page_Load. To figure out why other events are not firing, first understand why Page_Load is firing. It has a delegate defined in private void InitializeCompo nent()... this.Load += new System.EventHan dler(this.Page_ Load);

What that line specifies is that for the this.Load event, execute the code in the Page_Load procedure.
The syntax is something like this:
this.Load += new System.EventHan dler(this.Page_ Load);
someObjectOrCon trol.EventName += new System.EventHan dler(thisClass. EventProcedureN ame);
So, what you need to do is add a delegate (like currently specified for Page_Load) for each of the events you want to handle. You already have one, but I suspect it's in the wrong place. Find the following line in your code:
lst.SelectedInd exChanged+=new EventHandler(ls t_SelectedIndex Changed);
and move it to your private void InitializeCompo nent() routine. Also, for fun, try to be consistent with what the framework already does by specifying "new System.EventHan dler"... rather than "new EventHandler" (yes, you could probably get away without specifying system because you have using System; but just for consistency, blah blah blah.

Also, get some indentation going so you can see exactly where your namespace begins and ends, where the class begins and ends, etc. Make your code more readable and you might be able to eyeball some issues.

Also, don't expect Console.WriteLi ne to work in an asp.net Web app. you might try Response.Write( "Hello World"); instead.

HTH

"Mike" <no****@nospam. com> wrote in message news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..

Hi,

I am adding controls dynamically in a WebForm, but none of these controls' events fire. Here is the class code I am using. I have tried so many things, but nothing works :-(

namespace WebApplication1

{

using System;

using System.Data;

using System.Collecti ons;

using System.Drawing;

using System.Web;

using System.Web.UI;

using System.Web.UI.W ebControls;

using System.Web.UI.H tmlControls;

using System.Componen tModel;

/// <summary>

/// Summary description for WebUserControl1 .

/// </summary>

public class Tracking : System.Web.UI.W ebControls.WebC ontrol

{

private ArrayList arr = new ArrayList();

private System.Web.UI.W ebControls.Tabl e m_Table = new Table();

private System.Web.UI.W ebControls.Butt on btn = new Button();

//private System.Web.UI.W ebControls.Labe l lbl = new Label();

//private System.Web.UI.W ebControls.Imag e img = new System.Web.UI.W ebControls.Imag e();

//private System.Web.UI.W ebControls.Drop DownList lst = new DropDownList();

public void buildTable(Tabl eTracking trk)

{

//m_Table.BorderS tyle = BorderStyle.Sol id;

//m_Table.BorderW idth = Unit.Pixel(2);

//m_Table.BorderC olor = Color.DarkBlue;

System.Web.UI.W ebControls.Tabl eRow row = new TableRow();

System.Web.UI.W ebControls.Tabl eCell cell = new TableCell();

System.Web.UI.W ebControls.Imag e img = new System.Web.UI.W ebControls.Imag e();

if (trk.Editable== true)

{

//btn.Text = "<font face=Verdana size=1>" + "Edit Me";

btn.Text = "Edit";

img.ImageUrl = "Images/img_sec/edit_pencil.gif ";

cell.Height = 5;

//cell.Horizontal Align = HorizontalAlign .Right;

cell.Width = m_Table.Width;

cell.Controls.A dd(img);

cell.Controls.A dd(new LiteralControl( "&nbsp;"));

//cell.Controls.A dd(new LiteralControl( "<font face=Verdana size=1>"));

cell.Controls.A dd(btn);
row.Cells.Add(c ell);

m_Table.Rows.Ad d(row);

}

else

{

btn.Visible = false;

img.Visible = false;

}

m_Table.Width = trk.Width;

m_Table.Height = trk.Height;

}

public void buildItem(Array List items)

{

System.Web.UI.W ebControls.Tabl eRow row = new TableRow();

System.Web.UI.W ebControls.Tabl eCell cell = null;
//cell.BorderStyl e = BorderStyle.Sol id;

//cell.BorderWidt h = Unit.Pixel(1);

//cell.BorderColo r = Color.DarkBlue;

int currentRow = 0;

int previousRow = 0;

foreach (Item i in items)

{

currentRow = i.Row;

if (currentRow != previousRow && previousRow != 0)

{

m_Table.Rows.Ad d(row);

row = new TableRow();

}

cell = new TableCell();

cell.Horizontal Align = HorizontalAlign .Center;

cell.Width = i.Width;

//cell.Height = Convert.ToStrin g(i.Height);

if (i.Type == "Label")

{

System.Web.UI.W ebControls.Labe l lbl = new Label();

cell.Controls.A dd(new LiteralControl( "<font style='FONT-WEIGHT: bold' face=Verdana size=1>"));

lbl.Text = (string)i.Conte nt[0];

cell.Controls.A dd(lbl);

}

else if (i.Type == "Image")

{

System.Web.UI.W ebControls.Imag e img = new System.Web.UI.W ebControls.Imag e();

img.ImageUrl = (string)i.Conte nt[0];

cell.Controls.A dd(img);

}

else if (i.Type == "DropDownLi st")

{

System.Web.UI.W ebControls.Drop DownList lst = new DropDownList();

arr.Add(lst);

for (int n=0; n<i.Content.Cou nt; n++)

{

lst.Items.Add(( string)i.Conten t[n]);

}

lst.Visible = false;

cell.Controls.A dd(lst);

lst.SelectedInd exChanged+=new EventHandler(ls t_SelectedIndex Changed);

}

row.Cells.Add(c ell);

previousRow = i.Row;

}

m_Table.Rows.Ad d(row);

}

protected override void Render(HtmlText Writer writer)

{

Controls.Clear( );

Controls.Add(m_ Table);

base.Render (writer);

}

private void Page_Load(objec t sender, System.EventArg s e)

{

if (Page.IsPostBac k)

{

foreach(DropDow nList lst in arr)

{

lst.Visible = true;

}

btn.Text = "Save";

}

}
#region Web Form Designer generated code

override protected void OnInit(EventArg s e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeCompo nent();

base.OnInit(e);

}
/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeCompo nent()

{

this.Load += new System.EventHan dler(this.Page_ Load);

}

#endregion

private void lst_SelectedInd exChanged(objec t sender, EventArgs e)

{

Console.WriteLi ne("OK");

}

}

}
This is how the control is set up in the Web Form:
<WEBAPPLICATION 1:TRACKING id=trck1 runat=server></WEBAPPLICATION1 :TRACKING>

Any idea on what could be wrong?

Thanks.
Mike

Nov 18 '05 #2
Hi Mike

Robert is right about the missing delegates. They are usually added
automatically to the InitializeCompo nent method when you drag a control
onto the form in VS.net. A word of warning though. I have had a lot of
trouble, as have a lot of other people if you check through the
newsgroups, with manually adding items to the InitializeCompo nent
method. There is a good reason why the comment says 'do not modify
the contents of this method with the code editor.' It seems that each
time you go into design view, or make a change in design view, Visual
Studio deletes and rewrites the contents of this method. I have found
that often it isn't too successful in doing this if you have altered the
contents of the method and consequently events seem to stop firing as
the delegates have been erased. This has been fixed in .NET 2.0 with the
introduction of partial classess but in 1.1 the best workaround I could
come up with is to not put them in there in the first place but to put
them in the constructor where they will be left alone by VS.

Hope this helps

Graham
Robert Howells wrote:
I may be wrong, but suspect that you actually have one event firing -
Page_Load. To figure out why other events are not firing, first
understand why Page_Load is firing. It has a delegate defined in private
void InitializeCompo nent()... this.Load += new
System.EventHan dler(this.Page_ Load);

What that line specifies is that for the this.Load event, execute the
code in the Page_Load procedure.
The syntax is something like this:
this.Load += new System.EventHan dler(this.Page_ Load);
someObjectOrCon trol.EventName += new
System.EventHan dler(thisClass. EventProcedureN ame);
So, what you need to do is add a delegate (like currently specified for
Page_Load) for each of the events you want to handle. You already have
one, but I suspect it's in the wrong place. Find the following line in
your code:
lst.SelectedInd exChanged+=new EventHandler(ls t_SelectedIndex Changed);
and move it to your private void InitializeCompo nent() routine. Also,
for fun, try to be consistent with what the framework already does by
specifying "new System.EventHan dler"... rather than "new EventHandler"
(yes, you could probably get away without specifying system because you
have using System; but just for consistency, blah blah blah.

Also, get some indentation going so you can see exactly where your
namespace begins and ends, where the class begins and ends, etc. Make
your code more readable and you might be able to eyeball some issues.

Also, don't expect Console.WriteLi ne to work in an asp.net Web app. you
might try Response.Write( "Hello World"); instead.

HTH


"Mike" <no****@nospam. com <mailto:no****@ nospam.com>> wrote in
message news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..

Hi,

I am adding controls dynamically in a WebForm, but none of these
controls' events fire. Here is the class code I am using. I have
tried so many things, but nothing works :-(
namespace WebApplication1

{

using System;

using System.Data;

using System.Collecti ons;

using System.Drawing;

using System.Web;

using System.Web.UI;

using System.Web.UI.W ebControls;

using System.Web.UI.H tmlControls;

using System.Componen tModel;

/// <summary>

/// Summary description for WebUserControl1 .

/// </summary>

public class Tracking : System.Web.UI.W ebControls.WebC ontrol

{

private ArrayList arr = new ArrayList();

private System.Web.UI.W ebControls.Tabl e m_Table = new Table();

private System.Web.UI.W ebControls.Butt on btn = new Button();

//private System.Web.UI.W ebControls.Labe l lbl = new Label();

//private System.Web.UI.W ebControls.Imag e img = new
System.Web.UI.W ebControls.Imag e();

//private System.Web.UI.W ebControls.Drop DownList lst = new
DropDownList();

public void buildTable(Tabl eTracking trk)

{

//m_Table.BorderS tyle = BorderStyle.Sol id;

//m_Table.BorderW idth = Unit.Pixel(2);

//m_Table.BorderC olor = Color.DarkBlue;

System.Web.UI.W ebControls.Tabl eRow row = new TableRow();

System.Web.UI.W ebControls.Tabl eCell cell = new TableCell();

System.Web.UI.W ebControls.Imag e img = new
System.Web.UI.W ebControls.Imag e();

if (trk.Editable== true)

{

//btn.Text = "<font face=Verdana size=1>" + "Edit Me";

btn.Text = "Edit";

img.ImageUrl = "Images/img_sec/edit_pencil.gif ";

cell.Height = 5;

//cell.Horizontal Align = HorizontalAlign .Right;

cell.Width = m_Table.Width;

cell.Controls.A dd(img);

cell.Controls.A dd(new LiteralControl( "&nbsp;"));

//cell.Controls.A dd(new LiteralControl( "<font face=Verdana size=1>"));

cell.Controls.A dd(btn);

row.Cells.Add(c ell);

m_Table.Rows.Ad d(row);

}

else

{

btn.Visible = false;

img.Visible = false;

}

m_Table.Width = trk.Width;

m_Table.Height = trk.Height;

}

public void buildItem(Array List items)

{

System.Web.UI.W ebControls.Tabl eRow row = new TableRow();

System.Web.UI.W ebControls.Tabl eCell cell = null;

//cell.BorderStyl e = BorderStyle.Sol id;

//cell.BorderWidt h = Unit.Pixel(1);

//cell.BorderColo r = Color.DarkBlue;

int currentRow = 0;

int previousRow = 0;

foreach (Item i in items)

{

currentRow = i.Row;

if (currentRow != previousRow && previousRow != 0)

{

m_Table.Rows.Ad d(row);

row = new TableRow();

}

cell = new TableCell();

cell.Horizontal Align = HorizontalAlign .Center;

cell.Width = i.Width;

//cell.Height = Convert.ToStrin g(i.Height);

if (i.Type == "Label")

{

System.Web.UI.W ebControls.Labe l lbl = new Label();

cell.Controls.A dd(new LiteralControl( "<font style='FONT-WEIGHT:
bold' face=Verdana size=1>"));

lbl.Text = (string)i.Conte nt[0];

cell.Controls.A dd(lbl);

}

else if (i.Type == "Image")

{

System.Web.UI.W ebControls.Imag e img = new
System.Web.UI.W ebControls.Imag e();

img.ImageUrl = (string)i.Conte nt[0];

cell.Controls.A dd(img);

}

else if (i.Type == "DropDownLi st")

{

System.Web.UI.W ebControls.Drop DownList lst = new DropDownList();

arr.Add(lst);

for (int n=0; n<i.Content.Cou nt; n++)

{

lst.Items.Add(( string)i.Conten t[n]);

}

lst.Visible = false;

cell.Controls.A dd(lst);

lst.SelectedInd exChanged+=new EventHandler(ls t_SelectedIndex Changed);

}

row.Cells.Add(c ell);

previousRow = i.Row;

}

m_Table.Rows.Ad d(row);

}

protected override void Render(HtmlText Writer writer)

{

Controls.Clear( );

Controls.Add(m_ Table);

base.Render (writer);

}

private void Page_Load(objec t sender, System.EventArg s e)

{

if (Page.IsPostBac k)

{

foreach(DropDow nList lst in arr)

{

lst.Visible = true;

}

btn.Text = "Save";

}

}

#region Web Form Designer generated code

override protected void OnInit(EventArg s e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeCompo nent();

base.OnInit(e);

}

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeCompo nent()

{

this.Load += new System.EventHan dler(this.Page_ Load);

}

#endregion

private void lst_SelectedInd exChanged(objec t sender, EventArgs e)

{

Console.WriteLi ne("OK");

}

}

}
This is how the control is set up in the Web Form:
<WEBAPPLICATION 1:TRACKING id=trck1
runat=server></WEBAPPLICATION1 :TRACKING>

Any idea on what could be wrong?

Thanks.
Mike

Nov 18 '05 #3

Thanks Guys, your explanations were very helpful. I also found that removing the "Controls.Clear " statement from the "Render" method helped. With regards to the event handlers and delegates, I decided to keep them just after the instantiation of the dynamic control that I add to the Web Form.

Again, thanks a lot.
Mike

"Graham Pengelly" <gr****@REMOVEM Emainlineconsul tants.com> wrote in message news:Od******** ******@TK2MSFTN GP10.phx.gbl...
Hi Mike

Robert is right about the missing delegates. They are usually added
automatically to the InitializeCompo nent method when you drag a control
onto the form in VS.net. A word of warning though. I have had a lot of
trouble, as have a lot of other people if you check through the
newsgroups, with manually adding items to the InitializeCompo nent
method. There is a good reason why the comment says 'do not modify
the contents of this method with the code editor.' It seems that each
time you go into design view, or make a change in design view, Visual
Studio deletes and rewrites the contents of this method. I have found
that often it isn't too successful in doing this if you have altered the
contents of the method and consequently events seem to stop firing as
the delegates have been erased. This has been fixed in .NET 2.0 with the
introduction of partial classess but in 1.1 the best workaround I could
come up with is to not put them in there in the first place but to put
them in the constructor where they will be left alone by VS.

Hope this helps

Graham
Robert Howells wrote:
I may be wrong, but suspect that you actually have one event firing -
Page_Load. To figure out why other events are not firing, first
understand why Page_Load is firing. It has a delegate defined in private
void InitializeCompo nent()... this.Load += new
System.EventHan dler(this.Page_ Load);

What that line specifies is that for the this.Load event, execute the
code in the Page_Load procedure.
The syntax is something like this:
this.Load += new System.EventHan dler(this.Page_ Load);
someObjectOrCon trol.EventName += new
System.EventHan dler(thisClass. EventProcedureN ame);


So, what you need to do is add a delegate (like currently specified for
Page_Load) for each of the events you want to handle. You already have
one, but I suspect it's in the wrong place. Find the following line in
your code:
lst.SelectedInd exChanged+=new EventHandler(ls t_SelectedIndex Changed);
and move it to your private void InitializeCompo nent() routine. Also,
for fun, try to be consistent with what the framework already does by
specifying "new System.EventHan dler"... rather than "new EventHandler"
(yes, you could probably get away without specifying system because you
have using System; but just for consistency, blah blah blah.

Also, get some indentation going so you can see exactly where your
namespace begins and ends, where the class begins and ends, etc. Make
your code more readable and you might be able to eyeball some issues.

Also, don't expect Console.WriteLi ne to work in an asp.net Web app. you
might try Response.Write( "Hello World"); instead.

HTH






"Mike" <no****@nospam. com <mailto:no****@ nospam.com>> wrote in
message news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..

Hi,

I am adding controls dynamically in a WebForm, but none of these
controls' events fire. Here is the class code I am using. I have
tried so many things, but nothing works :-(


namespace WebApplication1

{

using System;

using System.Data;

using System.Collecti ons;

using System.Drawing;

using System.Web;

using System.Web.UI;

using System.Web.UI.W ebControls;

using System.Web.UI.H tmlControls;

using System.Componen tModel;

/// <summary>

/// Summary description for WebUserControl1 .

/// </summary>

public class Tracking : System.Web.UI.W ebControls.WebC ontrol

{

private ArrayList arr = new ArrayList();

private System.Web.UI.W ebControls.Tabl e m_Table = new Table();

private System.Web.UI.W ebControls.Butt on btn = new Button();

//private System.Web.UI.W ebControls.Labe l lbl = new Label();

//private System.Web.UI.W ebControls.Imag e img = new
System.Web.UI.W ebControls.Imag e();

//private System.Web.UI.W ebControls.Drop DownList lst = new
DropDownList();

public void buildTable(Tabl eTracking trk)

{

//m_Table.BorderS tyle = BorderStyle.Sol id;

//m_Table.BorderW idth = Unit.Pixel(2);

//m_Table.BorderC olor = Color.DarkBlue;

System.Web.UI.W ebControls.Tabl eRow row = new TableRow();

System.Web.UI.W ebControls.Tabl eCell cell = new TableCell();

System.Web.UI.W ebControls.Imag e img = new
System.Web.UI.W ebControls.Imag e();

if (trk.Editable== true)

{

//btn.Text = "<font face=Verdana size=1>" + "Edit Me";

btn.Text = "Edit";

img.ImageUrl = "Images/img_sec/edit_pencil.gif ";

cell.Height = 5;

//cell.Horizontal Align = HorizontalAlign .Right;

cell.Width = m_Table.Width;

cell.Controls.A dd(img);

cell.Controls.A dd(new LiteralControl( "&nbsp;"));

//cell.Controls.A dd(new LiteralControl( "<font face=Verdana size=1>"));

cell.Controls.A dd(btn);

row.Cells.Add(c ell);

m_Table.Rows.Ad d(row);

}

else

{

btn.Visible = false;

img.Visible = false;

}

m_Table.Width = trk.Width;

m_Table.Height = trk.Height;

}

public void buildItem(Array List items)

{

System.Web.UI.W ebControls.Tabl eRow row = new TableRow();

System.Web.UI.W ebControls.Tabl eCell cell = null;

//cell.BorderStyl e = BorderStyle.Sol id;

//cell.BorderWidt h = Unit.Pixel(1);

//cell.BorderColo r = Color.DarkBlue;

int currentRow = 0;

int previousRow = 0;

foreach (Item i in items)

{

currentRow = i.Row;

if (currentRow != previousRow && previousRow != 0)

{

m_Table.Rows.Ad d(row);

row = new TableRow();

}

cell = new TableCell();

cell.Horizontal Align = HorizontalAlign .Center;

cell.Width = i.Width;

//cell.Height = Convert.ToStrin g(i.Height);

if (i.Type == "Label")

{

System.Web.UI.W ebControls.Labe l lbl = new Label();

cell.Controls.A dd(new LiteralControl( "<font style='FONT-WEIGHT:
bold' face=Verdana size=1>"));

lbl.Text = (string)i.Conte nt[0];

cell.Controls.A dd(lbl);

}

else if (i.Type == "Image")

{

System.Web.UI.W ebControls.Imag e img = new
System.Web.UI.W ebControls.Imag e();

img.ImageUrl = (string)i.Conte nt[0];

cell.Controls.A dd(img);

}

else if (i.Type == "DropDownLi st")

{

System.Web.UI.W ebControls.Drop DownList lst = new DropDownList();

arr.Add(lst);

for (int n=0; n<i.Content.Cou nt; n++)

{

lst.Items.Add(( string)i.Conten t[n]);

}

lst.Visible = false;

cell.Controls.A dd(lst);

lst.SelectedInd exChanged+=new EventHandler(ls t_SelectedIndex Changed);

}

row.Cells.Add(c ell);

previousRow = i.Row;

}

m_Table.Rows.Ad d(row);

}

protected override void Render(HtmlText Writer writer)

{

Controls.Clear( );

Controls.Add(m_ Table);

base.Render (writer);

}

private void Page_Load(objec t sender, System.EventArg s e)

{

if (Page.IsPostBac k)

{

foreach(DropDow nList lst in arr)

{

lst.Visible = true;

}

btn.Text = "Save";

}

}

#region Web Form Designer generated code

override protected void OnInit(EventArg s e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeCompo nent();

base.OnInit(e);

}

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeCompo nent()

{

this.Load += new System.EventHan dler(this.Page_ Load);

}

#endregion

private void lst_SelectedInd exChanged(objec t sender, EventArgs e)

{

Console.WriteLi ne("OK");

}

}

}


This is how the control is set up in the Web Form:
<WEBAPPLICATION 1:TRACKING id=trck1
runat=server></WEBAPPLICATION1 :TRACKING>

Any idea on what could be wrong?

Thanks.
Mike


Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5040
by: teb | last post by:
Hello all, Here is basically the situation. I have an empty div on my page. When I mouseover a word, the innerHTML of the div gets written with a table. The td elements all have onclick, onmouseover, etc. events. When I mouseover a word, the div appears, but none of the events fire until another event occurs. For example, if I put in an alert box or I right click, and then mouseover the div, the td events then work. Keep in mind that...
14
12146
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using events since I never saw it used anywhere in MSDN documentation/samples?! Or it will just break when I upgrade to .NET Framework 2.x in the coming years namespace MyNamespac public delegate void MyDel() public class MyBase public virtual...
9
2307
by: Erik Frey | last post by:
Hi there, Just curious as to whether there's a clever way to see the events a control/object is firing off, perhaps written out to the debug console. It would be really handy to know which events a control is firing when I perform a certain action, and the order in which they are occurring. Thanks, Erik
7
4584
by: Denise | last post by:
I just realized the DataTable_RowChanging events were firing when I called Fill method of the DataAdapter! It fires TWICE for each row loaded. I thought these were only supposed to be called when data was actually being edited. I am using bound textbox controls on the form. Could that have anything to do with it? Does anyone know how to stop the RowChanging events from firing? Thanks!
0
1209
by: RobKinney1 | last post by:
Hello, One of our C# apps (2.0) depends on a few events. One of them being DocumentComplete. Well, everything works fine with users that have IE 6 installed on their computers. But we noticed here in testing that if we have IE 7 installed, these events don't even fire in our application. We also tried using the DownloadComplete event but that is not firing either. We uninstalled IE 7 and reverted to 6. Then everything worked...
2
2666
by: mswlogo | last post by:
I looked high and low for code to do this and finally found some VB code that did it right. This is a C# flavor of it. public event EventHandler<EventArgsMyEventToBeFired; public void FireEvent(Guid instanceId, string handler) { EventArgs e = new EventArgs(instanceId);
1
1745
by: TimmyTurner | last post by:
Hi all I'm working on a ASP.NET, C# project on Visual Studio 2005, using a MSDB in _vista_. My problem is that the events for the buttons are not firing. I've searched the web and the solution suggested was to call the "aspnet_regiis.exe -c" command. I got an error about administrator rights, then set the corresponding folder off read only like suggested. But this did not work, and the events are still not firing I'm not sure if...
4
2054
by: jehugaleahsa | last post by:
Hello: Is there a way to prevent one event from firing while another event is already being fired? I have a tool that extracts media from web pages and it has multiple events firing when the status of the download changes. Some of the events are used to tell the next file to download while others manager other resources. However, on occasion, one event will
4
2044
by: Joergen Bech | last post by:
I sometimes use delegates for broadcasting "StateChanged" events, i.e. if I have multiple forms and/or controls that need updating at the same time as the result of a change in a global/common object, I keep local references to this object in each UI object, e.g. Private WithEvents _tools As RepeatTools and catch messages in an event handler like this:
0
10136
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9989
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9925
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8814
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.