473,775 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic Controls and Page_Init


Hello again to all of you geniuses,

I'm having a problem trying to load dynamic controls at the initialization phase.

I've read the docs, and I thought I had it figured out:
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
.NET Framework Class Library

Control.Init Event [C#]

C#
public event EventHandler Init;

Event Data
The event handler receives an argument of type EventArgs.

Remarks
Server controls should perform any initialization steps that are required
to create and set up an instance. You cannot use view-state information
within this event; it is not populated yet. You should not access another
server control during this event, regardless of whether it is a child or
parent to this control. Other server controls are not certain to be created
and ready for access.

Example
[C#] The following example assigns a custom event handler, Control_Init,
to the Init event of a control, myControl, when the Page_Init method is
called on the page that contains the control.

[C#]
void Page_Init(objec t sender,EventArg s e)
{
// Add a event Handler for 'Init'.
myControl.Init += new System.EventHan dler(Control_In it);
}

void Control_Init(ob ject sender,EventArg s e)
{
Response.Write( "The ID of the object initially : " + myControl.ID);
// Change the ID property.
myControl.ID="T estControl";
Response.Write( "<br>The changed ID : " + myControl.ID);
}

© 2001-2002 Microsoft Corporation. All rights reserved.

<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>

One thing I don't understand is: Where did "myControl" come from in the
given example?

In my own effort, I tried to attach a literal control to a placeholder:
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>

void Page_Init(objec t sender,EventArg s e)
{
// Add a event Handler for 'Init'.
// myControl.Init += new System.EventHan dler(Control_In it);
PlaceHolder plc_hldr = (PlaceHolder) FindControl ("Dyn_Control_P laceholder");
plc_hldr.Init += new System.EventHan dler (plc_hldr_Contr ol_Init);
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void plc_hldr_Contro l_Init (object sender,EventArg s e)
{
Label lbl_msg01 = (Label) FindControl ("Message01" );

Dyn_Control_Pla ceholder.Contro ls.Add
( new LiteralControl( "<br>added 1 on init<br>") );
PlaceHolder plc_hldr = (PlaceHolder) FindControl ("Dyn_Control_P laceholder");

lbl_msg01.Text = "The ID of the object initially : " + plc_hldr.ID;
Response.Write( "The ID of the object initially : " + plc_hldr.ID);

plc_hldr.Contro ls.Add ( new LiteralControl( "<br>added 2 on init<br>") );
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>

... and nothing happened - the literal control was not there.

I'm hoping that someone smarter than me can clue me in on this
- I would be most grateful.

My complete code is as follows:
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<%@ Page Language="C#" AutoEventWireup ="True" %>

<html>
<head>

<script runat="server">

/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

/* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- */
public class sys_obj_class
{
private ControlCollecti on pram_ph01_ctrl;
public ControlCollecti on Get_pram_ph01_c trl
{ get { return pram_ph01_ctrl; } }

private Page this_page01;
public Page Get_this_page01
{ get { return this_page01; } }

private PlaceHolder Obj_Dyn_Ctrl_Pl aceholder;
public PlaceHolder Get_Obj_Dyn_Ctr l_Placeholder
{ get { return Obj_Dyn_Ctrl_Pl aceholder; } }

private Label Obj_Dyn_Label01 ;
public Label Get_Obj_Dyn_Lab el01
{ get { return Obj_Dyn_Label01 ; } }
public sys_obj_class
(PlaceHolder Dyn_Ctrl_Placeh older, Label Dyn_Label)
{ pram_ph01_ctrl = Dyn_Ctrl_Placeh older.Controls;
this_page01 = Dyn_Ctrl_Placeh older.Page;
Obj_Dyn_Ctrl_Pl aceholder = Dyn_Ctrl_Placeh older;
Obj_Dyn_Label01 = Dyn_Label;
}
}

/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void Page_Init(objec t sender,EventArg s e)
{
// Add a event Handler for 'Init'.
// myControl.Init += new System.EventHan dler(Control_In it);
PlaceHolder plc_hldr = (PlaceHolder) FindControl ("Dyn_Control_P laceholder");
plc_hldr.Init += new System.EventHan dler(plc_hldr_C ontrol_Init);
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void plc_hldr_Contro l_Init (object sender,EventArg s e)
{
Label lbl_msg01 = (Label) FindControl ("Message01" );
PlaceHolder plc_hldr = (PlaceHolder) FindControl ("Dyn_Control_P laceholder");

lbl_msg01.Text = "The ID of the object initially : " + plc_hldr.ID;
Response.Write( "The ID of the object initially : " + plc_hldr.ID);

plc_hldr.Contro ls.Add ( new LiteralControl( "<br>added on init<br>") );
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
protected void Page_Load (Object sender, EventArgs e)
{
PlaceHolder plc_hldr = (PlaceHolder) FindControl ("Dyn_Control_P laceholder");
Label lbl_msg01 = (Label) FindControl ("Message01" );
sys_obj_class sys_obj = new sys_obj_class (plc_hldr, lbl_msg01);

ctrl_pair_creat ion_01 ccp1 = new ctrl_pair_creat ion_01 (sys_obj);

ccp1.create_ctr l_pair_01 ();
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
protected class base_create_ctr l_pair
{
protected TextBox UserTextBox0x;
protected Button button0x;
protected ControlCollecti on ph01_ctrl;
protected PlaceHolder base_Dyn_Ctrl_P laceholder;
protected Label Dyn_Lbl_msg01;

// constructor
protected base_create_ctr l_pair (sys_obj_class sys_obj)
{ ph01_ctrl = sys_obj.Get_pra m_ph01_ctrl;
base_Dyn_Ctrl_P laceholder = sys_obj.Get_Obj _Dyn_Ctrl_Place holder;
Dyn_Lbl_msg01 = sys_obj.Get_Obj _Dyn_Label01;
}

protected TextBox create_text_box _control (String text_box_id)
{ // Create UserTextBox TextBox control.
TextBox new_TextBox = new TextBox ();

// Configure the UserTextBox TextBox control.
new_TextBox.ID = text_box_id;

// Add UserTextBox TextBox control to the Controls collection
// of the Dyn_Control_Pla ceholder PlaceHolder control.
ph01_ctrl.Add (new_TextBox);

return new_TextBox;
}

/* --------------------------------------------------------- *
Example: The following example creates a Button,
sets its DialogResult property to DialogResult.OK ,
and adds it to a Form.
* --------------------------------------------------------- */
protected void InitializeMyBut ton (String Btn_ID, String Btn_text)
{ // Create and initialize a Button.
button0x = new Button();
button0x.ID = Btn_ID;
button0x.Text = Btn_text;

ph01_ctrl.Add ( new LiteralControl( "<br><br>") );
ph01_ctrl.Add (button0x);
}

protected void init_single_lin e_text_box (TextBox new_TextBox, int col_sz)
{ new_TextBox.Col umns = col_sz; }

protected void create_ctrl_pai r_0x
(String TB_ID, String DB_ID, String DB_txt)
{ // Create UserTextBox TextBox control.
UserTextBox0x = create_text_box _control (TB_ID);
InitializeMyBut ton(DB_ID, DB_txt);
}

/* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- */
private String submit_click_st r01 = "The TextBox";

private String submit_click_st r02
= " control above is dynamically generated. <br> You entered: ";
public void Submit_Click (Object sender, EventArgs e)
{ // Retrieve the UserTextBox TextBox control from the
Dyn_Control_Pla ceholder
// PlaceHolder control.
TextBox TempTextBox = (TextBox)
base_Dyn_Ctrl_P laceholder.Find Control("UserTe xtBox1");

// Display the Text property.
Dyn_Lbl_msg01.T ext = submit_click_st r01 + '1' + submit_click_st r02 +
TempTextBox.Tex t;
}
/* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- */

}
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
protected class ctrl_pair_creat ion_01 : base_create_ctr l_pair
{
private sys_obj_class lcl_sys_obj;

// constructor
public ctrl_pair_creat ion_01 (sys_obj_class sys_obj) : base (sys_obj)
{ lcl_sys_obj = sys_obj; }

/* . . . . . . . . . . . . . */
public void create_ctrl_pai r_01 ()
{ create_ctrl_pai r_0x
("UserTextBox1" , "DButton01" , "Submit 01");

button0x.Click += new EventHandler (Submit_Click);

if (!lcl_sys_obj.G et_this_page01. IsPostBack)
init_single_lin e_text_box (UserTextBox0x, 22);

ph01_ctrl.Add ( new LiteralControl( "<br><br>") );
}
/* . . . . . . . . . . . . . */
}
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */

</script>
</head>

<body>

<form runat="server">

<h3> Control Init </h3>

Enter some text and click the Submit button. <br><br>

<asp:PlaceHolde r ID="Dyn_Control _Placeholder" runat="server"/>

<asp:Label ID="Message01" runat="server"/>

</form>

</body>
</html>

<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
- wASP
Nov 17 '05 #1
9 17626
This is an example of dynamically adding an event handler to a control. They
are assuming the control is already there.

"wASP" <wylbur[at]ev1[dot]net> wrote in message
news:r6******** *************** *********@4ax.c om...

Hello again to all of you geniuses,

I'm having a problem trying to load dynamic controls at the initialization
phase.

I've read the docs, and I thought I had it figured out:
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
.NET Framework Class Library

Control.Init Event [C#]

C#
public event EventHandler Init;

Event Data
The event handler receives an argument of type EventArgs.

Remarks
Server controls should perform any initialization steps that are required
to create and set up an instance. You cannot use view-state information
within this event; it is not populated yet. You should not access another
server control during this event, regardless of whether it is a child or
parent to this control. Other server controls are not certain to be
created
and ready for access.

Example
[C#] The following example assigns a custom event handler, Control_Init,
to the Init event of a control, myControl, when the Page_Init method is
called on the page that contains the control.

[C#]
void Page_Init(objec t sender,EventArg s e)
{
// Add a event Handler for 'Init'.
myControl.Init += new System.EventHan dler(Control_In it);
}

void Control_Init(ob ject sender,EventArg s e)
{
Response.Write( "The ID of the object initially : " + myControl.ID);
// Change the ID property.
myControl.ID="T estControl";
Response.Write( "<br>The changed ID : " + myControl.ID);
}

© 2001-2002 Microsoft Corporation. All rights reserved.

<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>

One thing I don't understand is: Where did "myControl" come from in the
given example?

In my own effort, I tried to attach a literal control to a placeholder:
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>

void Page_Init(objec t sender,EventArg s e)
{
// Add a event Handler for 'Init'.
// myControl.Init += new System.EventHan dler(Control_In it);
PlaceHolder plc_hldr = (PlaceHolder) FindControl
("Dyn_Control_P laceholder");
plc_hldr.Init += new System.EventHan dler (plc_hldr_Contr ol_Init);
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void plc_hldr_Contro l_Init (object sender,EventArg s e)
{
Label lbl_msg01 = (Label) FindControl ("Message01" );

Dyn_Control_Pla ceholder.Contro ls.Add
( new LiteralControl( "<br>added 1 on init<br>") );
PlaceHolder plc_hldr = (PlaceHolder) FindControl
("Dyn_Control_P laceholder");

lbl_msg01.Text = "The ID of the object initially : " + plc_hldr.ID;
Response.Write( "The ID of the object initially : " + plc_hldr.ID);

plc_hldr.Contro ls.Add ( new LiteralControl( "<br>added 2 on
init<br>") );
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>

... and nothing happened - the literal control was not there.

I'm hoping that someone smarter than me can clue me in on this
- I would be most grateful.

My complete code is as follows:
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<%@ Page Language="C#" AutoEventWireup ="True" %>

<html>
<head>

<script runat="server">

/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

/* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
*/
public class sys_obj_class
{
private ControlCollecti on pram_ph01_ctrl;
public ControlCollecti on Get_pram_ph01_c trl
{ get { return pram_ph01_ctrl; } }

private Page this_page01;
public Page Get_this_page01
{ get { return this_page01; } }

private PlaceHolder Obj_Dyn_Ctrl_Pl aceholder;
public PlaceHolder Get_Obj_Dyn_Ctr l_Placeholder
{ get { return Obj_Dyn_Ctrl_Pl aceholder; } }

private Label Obj_Dyn_Label01 ;
public Label Get_Obj_Dyn_Lab el01
{ get { return Obj_Dyn_Label01 ; } }
public sys_obj_class
(PlaceHolder Dyn_Ctrl_Placeh older, Label Dyn_Label)
{ pram_ph01_ctrl = Dyn_Ctrl_Placeh older.Controls;
this_page01 = Dyn_Ctrl_Placeh older.Page;
Obj_Dyn_Ctrl_Pl aceholder = Dyn_Ctrl_Placeh older;
Obj_Dyn_Label01 = Dyn_Label;
}
}

/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void Page_Init(objec t sender,EventArg s e)
{
// Add a event Handler for 'Init'.
// myControl.Init += new System.EventHan dler(Control_In it);
PlaceHolder plc_hldr = (PlaceHolder) FindControl
("Dyn_Control_P laceholder");
plc_hldr.Init += new System.EventHan dler(plc_hldr_C ontrol_Init);
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void plc_hldr_Contro l_Init (object sender,EventArg s e)
{
Label lbl_msg01 = (Label) FindControl ("Message01" );
PlaceHolder plc_hldr = (PlaceHolder) FindControl
("Dyn_Control_P laceholder");

lbl_msg01.Text = "The ID of the object initially : " + plc_hldr.ID;
Response.Write( "The ID of the object initially : " + plc_hldr.ID);

plc_hldr.Contro ls.Add ( new LiteralControl( "<br>added on init<br>") );
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
protected void Page_Load (Object sender, EventArgs e)
{
PlaceHolder plc_hldr = (PlaceHolder) FindControl
("Dyn_Control_P laceholder");
Label lbl_msg01 = (Label) FindControl ("Message01" );
sys_obj_class sys_obj = new sys_obj_class (plc_hldr, lbl_msg01);

ctrl_pair_creat ion_01 ccp1 = new ctrl_pair_creat ion_01 (sys_obj);

ccp1.create_ctr l_pair_01 ();
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
protected class base_create_ctr l_pair
{
protected TextBox UserTextBox0x;
protected Button button0x;
protected ControlCollecti on ph01_ctrl;
protected PlaceHolder base_Dyn_Ctrl_P laceholder;
protected Label Dyn_Lbl_msg01;

// constructor
protected base_create_ctr l_pair (sys_obj_class sys_obj)
{ ph01_ctrl = sys_obj.Get_pra m_ph01_ctrl;
base_Dyn_Ctrl_P laceholder =
sys_obj.Get_Obj _Dyn_Ctrl_Place holder;
Dyn_Lbl_msg01 = sys_obj.Get_Obj _Dyn_Label01;
}

protected TextBox create_text_box _control (String text_box_id)
{ // Create UserTextBox TextBox control.
TextBox new_TextBox = new TextBox ();

// Configure the UserTextBox TextBox control.
new_TextBox.ID = text_box_id;

// Add UserTextBox TextBox control to the Controls collection
// of the Dyn_Control_Pla ceholder PlaceHolder control.
ph01_ctrl.Add (new_TextBox);

return new_TextBox;
}

/* --------------------------------------------------------- *
Example: The following example creates a Button,
sets its DialogResult property to DialogResult.OK ,
and adds it to a Form.
* --------------------------------------------------------- */
protected void InitializeMyBut ton (String Btn_ID, String
Btn_text)
{ // Create and initialize a Button.
button0x = new Button();
button0x.ID = Btn_ID;
button0x.Text = Btn_text;

ph01_ctrl.Add ( new LiteralControl( "<br><br>") );
ph01_ctrl.Add (button0x);
}

protected void init_single_lin e_text_box (TextBox new_TextBox,
int col_sz)
{ new_TextBox.Col umns = col_sz; }

protected void create_ctrl_pai r_0x
(String TB_ID, String DB_ID, String DB_txt)
{ // Create UserTextBox TextBox control.
UserTextBox0x = create_text_box _control (TB_ID);
InitializeMyBut ton(DB_ID, DB_txt);
}
/* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
*/
private String submit_click_st r01 = "The TextBox";

private String submit_click_st r02
= " control above is dynamically generated. <br> You
entered: ";
public void Submit_Click (Object sender, EventArgs e)
{ // Retrieve the UserTextBox TextBox control from the
Dyn_Control_Pla ceholder
// PlaceHolder control.
TextBox TempTextBox = (TextBox)
base_Dyn_Ctrl_P laceholder.Find Control("UserTe xtBox1");

// Display the Text property.
Dyn_Lbl_msg01.T ext = submit_click_st r01 + '1' +
submit_click_st r02 +
TempTextBox.Tex t;
}

/* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
*/

}
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
protected class ctrl_pair_creat ion_01 : base_create_ctr l_pair
{
private sys_obj_class lcl_sys_obj;

// constructor
public ctrl_pair_creat ion_01 (sys_obj_class sys_obj) : base
(sys_obj)
{ lcl_sys_obj = sys_obj; }

/* . . . . . . . . . . . . . */
public void create_ctrl_pai r_01 ()
{ create_ctrl_pai r_0x
("UserTextBox1" , "DButton01" , "Submit 01");

button0x.Click += new EventHandler (Submit_Click);

if (!lcl_sys_obj.G et_this_page01. IsPostBack)
init_single_lin e_text_box (UserTextBox0x, 22);

ph01_ctrl.Add ( new LiteralControl( "<br><br>") );
}
/* . . . . . . . . . . . . . */
}
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */
/* - - - - - - - - - - - - - - - - - - - - - - */

</script>
</head>

<body>

<form runat="server">

<h3> Control Init </h3>

Enter some text and click the Submit button. <br><br>

<asp:PlaceHolde r ID="Dyn_Control _Placeholder" runat="server"/>

<asp:Label ID="Message01" runat="server"/>

</form>

</body>
</html>

<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
- wASP

Nov 17 '05 #2
On Thu, 28 Jul 2005 14:16:18 -0400, "Marina" <so*****@nospam .com> wrote:
This is an example of dynamically adding an event handler to a control. They
are assuming the control is already there.


Hi Marina,

OK - so I'm trying to add a handler to a control that has yet to be instantiated?

Can you give me a clue as to how would I add a dynamic control
to a placeholder before Page_Load gets fired and the viewstate
is recovered on postback?

... or ...

How could I save the viewstate for a specific control (created dynamically)
then recover it on Page_Load? ... THAT is a more important question.
Do you know of any good docs/books that might spell it out for a fool like myself?

I'm a newbie on this - and I've got a lot to learn.

- wASP
Nov 17 '05 #3
No, the control in this example has been instantiated. It exists, it is
declared in the .aspx page, and by the time Init runs it points to a real
object.

In the Init or Load event, you would declare a variable of the type you
want. You would create an instance of whatever object it is you want, and
then add it to your placeholder. Then you would the handler to this object
you just created. If the page has viewstate on, the control should just
maintain its viewstate. You have to do this on every postback.

"wASP" <wylbur[at]ev1[dot]net> wrote in message
news:i8******** *************** *********@4ax.c om...
On Thu, 28 Jul 2005 14:16:18 -0400, "Marina" <so*****@nospam .com> wrote:
This is an example of dynamically adding an event handler to a control.
They
are assuming the control is already there.


Hi Marina,

OK - so I'm trying to add a handler to a control that has yet to be
instantiated?

Can you give me a clue as to how would I add a dynamic control
to a placeholder before Page_Load gets fired and the viewstate
is recovered on postback?

... or ...

How could I save the viewstate for a specific control (created
dynamically)
then recover it on Page_Load? ... THAT is a more important question.
Do you know of any good docs/books that might spell it out for a fool like
myself?

I'm a newbie on this - and I've got a lot to learn.

- wASP

Nov 17 '05 #4
On Thu, 28 Jul 2005 15:14:08 -0400, "Marina" <so*****@nospam .com> wrote:
No, the control in this example has been instantiated. It exists, it is
declared in the .aspx page, and by the time Init runs it points to a real
object.
Going back to my original post ...

So then this:

PlaceHolder plc_hldr = (PlaceHolder) FindControl ("Dyn_Control_P laceholder");

... should return a valid reference to the placeholder, right?

If not, then how would I get a valid reference?

In the Init or Load event, you would declare a variable of the type you
want. You would create an instance of whatever object it is you want, and
then add it to your placeholder. Then you would the handler to this object
you just created. If the page has viewstate on, the control should just
maintain its viewstate. You have to do this on every postback.
I thought I did that?

/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void Page_Init(objec t sender,EventArg s e)
{
// Add a event Handler for 'Init'.
PlaceHolder plc_hldr = (PlaceHolder) FindControl ("Dyn_Control_P laceholder");
plc_hldr.Init += new System.EventHan dler (plc_hldr_Contr ol_Init);
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void plc_hldr_Contro l_Init (object sender,EventArg s e)
{
Dyn_Control_Pla ceholder.Contro ls.Add
( new LiteralControl( "<br>added 1 on init<br>") );
...
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

I also tried doing this:

/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void plc_hldr_Contro l_Init (object sender,EventArg s e)
{
this.Controls.A dd
( new LiteralControl( "<br>added 1 on init<br>") );
...
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

... with the same (non)result.
You have to do this on every postback.
I realize this, but I can't even get it to work on the first posting
- never mind postback.

So am I just stupid or som'tin'?

In my own effort, I tried to attach a literal control to a placeholder:
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>

void Page_Init(objec t sender,EventArg s e)
{
// Add a event Handler for 'Init'.
// myControl.Init += new System.EventHan dler(Control_In it);
PlaceHolder plc_hldr = (PlaceHolder) FindControl ("Dyn_Control_P laceholder");
plc_hldr.Init += new System.EventHan dler (plc_hldr_Contr ol_Init);
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void plc_hldr_Contro l_Init (object sender,EventArg s e)
{
Label lbl_msg01 = (Label) FindControl ("Message01" );

Dyn_Control_Pla ceholder.Contro ls.Add
( new LiteralControl( "<br>added 1 on init<br>") );
PlaceHolder plc_hldr = (PlaceHolder) FindControl ("Dyn_Control_P laceholder");

lbl_msg01.Text = "The ID of the object initially : " + plc_hldr.ID;
Response.Write( "The ID of the object initially : " + plc_hldr.ID);

plc_hldr.Contro ls.Add ( new LiteralControl( "<br>added 2 on init<br>") );
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>



"wASP" <wylbur[at]ev1[dot]net> wrote in message
news:i8******* *************** **********@4ax. com...
On Thu, 28 Jul 2005 14:16:18 -0400, "Marina" <so*****@nospam .com> wrote:
This is an example of dynamically adding an event handler to a control.
They
are assuming the control is already there.


Hi Marina,

OK - so I'm trying to add a handler to a control that has yet to be
instantiated?

Can you give me a clue as to how would I add a dynamic control
to a placeholder before Page_Load gets fired and the viewstate
is recovered on postback?

... or ...

How could I save the viewstate for a specific control (created
dynamically)
then recover it on Page_Load? ... THAT is a more important question.
Do you know of any good docs/books that might spell it out for a fool like
myself?

I'm a newbie on this - and I've got a lot to learn.

- wASP


- wASP
Nov 17 '05 #5
Don't you already have a direct reference to this placeholder? You dragged
it on to the page, presumably. Which means a variable got created for it.

"wASP" <wylbur[at]ev1[dot]net> wrote in message
news:uv******** *************** *********@4ax.c om...
On Thu, 28 Jul 2005 15:14:08 -0400, "Marina" <so*****@nospam .com> wrote:
No, the control in this example has been instantiated. It exists, it is
declared in the .aspx page, and by the time Init runs it points to a real
object.


Going back to my original post ...

So then this:

PlaceHolder plc_hldr = (PlaceHolder) FindControl
("Dyn_Control_P laceholder");

... should return a valid reference to the placeholder, right?

If not, then how would I get a valid reference?

In the Init or Load event, you would declare a variable of the type you
want. You would create an instance of whatever object it is you want, and
then add it to your placeholder. Then you would the handler to this
object
you just created. If the page has viewstate on, the control should just
maintain its viewstate. You have to do this on every postback.


I thought I did that?

/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void Page_Init(objec t sender,EventArg s e)
{
// Add a event Handler for 'Init'.
PlaceHolder plc_hldr = (PlaceHolder) FindControl
("Dyn_Control_P laceholder");
plc_hldr.Init += new System.EventHan dler (plc_hldr_Contr ol_Init);
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void plc_hldr_Contro l_Init (object sender,EventArg s e)
{
Dyn_Control_Pla ceholder.Contro ls.Add
( new LiteralControl( "<br>added 1 on init<br>") );
...
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

I also tried doing this:

/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void plc_hldr_Contro l_Init (object sender,EventArg s e)
{
this.Controls.A dd
( new LiteralControl( "<br>added 1 on init<br>") );
...
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

... with the same (non)result.
You have to do this on every postback.


I realize this, but I can't even get it to work on the first posting
- never mind postback.

So am I just stupid or som'tin'?

In my own effort, I tried to attach a literal control to a placeholder:
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>

void Page_Init(objec t sender,EventArg s e)
{
// Add a event Handler for 'Init'.
// myControl.Init += new System.EventHan dler(Control_In it);
PlaceHolder plc_hldr = (PlaceHolder) FindControl
("Dyn_Control_P laceholder");
plc_hldr.Init += new System.EventHan dler (plc_hldr_Contr ol_Init);
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void plc_hldr_Contro l_Init (object sender,EventArg s e)
{
Label lbl_msg01 = (Label) FindControl ("Message01" );

Dyn_Control_Pla ceholder.Contro ls.Add
( new LiteralControl( "<br>added 1 on init<br>") );
PlaceHolder plc_hldr = (PlaceHolder) FindControl
("Dyn_Control_P laceholder");

lbl_msg01.Text = "The ID of the object initially : " + plc_hldr.ID;
Response.Write( "The ID of the object initially : " + plc_hldr.ID);

plc_hldr.Contro ls.Add ( new LiteralControl( "<br>added 2 on
init<br>") );
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>



"wASP" <wylbur[at]ev1[dot]net> wrote in message
news:i8****** *************** ***********@4ax .com...
On Thu, 28 Jul 2005 14:16:18 -0400, "Marina" <so*****@nospam .com> wrote:

This is an example of dynamically adding an event handler to a control.
They
are assuming the control is already there.

Hi Marina,

OK - so I'm trying to add a handler to a control that has yet to be
instantiated?

Can you give me a clue as to how would I add a dynamic control
to a placeholder before Page_Load gets fired and the viewstate
is recovered on postback?

... or ...

How could I save the viewstate for a specific control (created
dynamically)
then recover it on Page_Load? ... THAT is a more important question.
Do you know of any good docs/books that might spell it out for a fool
like
myself?

I'm a newbie on this - and I've got a lot to learn.

- wASP


- wASP

Nov 17 '05 #6
> PlaceHolder plc_hldr = (PlaceHolder) FindControl
("Dyn_Control_P laceholder");
plc_hldr.Init += new System.EventHan dler(plc_hldr_C ontrol_Init);


You can replace that with:

Dyn_Control_Pla ceholder.Init += new
System.EventHan dler(plc_hldr_C ontrol_Init);

Elements on the page are accessible by their ID.

I don't understand why your plc_hldr_Contro l_Init isn't called though. I
tried a very simple sample, with this code:

void Page_Init(objec t sender, EventArgs e)
{
myControl.Init += new System.EventHan dler(Control_In it);
}

void Control_Init(ob ject sender, EventArgs e)
{
Response.Write( "Control_In it called);
}

I could break on the Page_Init() function, but the breakpoint in
Control_Init() never went off. Perhaps someone else has a clue ?

Greetings,
Wessel
Nov 17 '05 #7
On Thu, 28 Jul 2005 15:40:44 -0400, "Marina" <so*****@nospam .com> wrote:
Don't you already have a direct reference to this placeholder? You dragged
it on to the page, presumably. Which means a variable got created for it.
I'm afraid I didn't drag anything onto any pages: I'm not using studio.
I'm just using notepad at this point.

I tried using Wessel's suggestion:

Dyn_Control_Pla ceholder.Init += new
System.EventHan dler(plc_hldr_C ontrol_Init);

... and that didn't work either.

wASP
=============== ===============

"wASP" <wylbur[at]ev1[dot]net> wrote in message
news:uv******* *************** **********@4ax. com...
On Thu, 28 Jul 2005 15:14:08 -0400, "Marina" <so*****@nospam .com> wrote:
No, the control in this example has been instantiated. It exists, it is
declared in the .aspx page, and by the time Init runs it points to a real
object.


Going back to my original post ...

So then this:

PlaceHolder plc_hldr = (PlaceHolder) FindControl
("Dyn_Control_P laceholder");

... should return a valid reference to the placeholder, right?

If not, then how would I get a valid reference?

In the Init or Load event, you would declare a variable of the type you
want. You would create an instance of whatever object it is you want, and
then add it to your placeholder. Then you would the handler to this
object
you just created. If the page has viewstate on, the control should just
maintain its viewstate. You have to do this on every postback.


I thought I did that?

/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void Page_Init(objec t sender,EventArg s e)
{
// Add a event Handler for 'Init'.
PlaceHolder plc_hldr = (PlaceHolder) FindControl
("Dyn_Control_P laceholder");
plc_hldr.Init += new System.EventHan dler (plc_hldr_Contr ol_Init);
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void plc_hldr_Contro l_Init (object sender,EventArg s e)
{
Dyn_Control_Pla ceholder.Contro ls.Add
( new LiteralControl( "<br>added 1 on init<br>") );
...
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

I also tried doing this:

/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void plc_hldr_Contro l_Init (object sender,EventArg s e)
{
this.Controls.A dd
( new LiteralControl( "<br>added 1 on init<br>") );
...
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

... with the same (non)result.
You have to do this on every postback.


I realize this, but I can't even get it to work on the first posting
- never mind postback.

So am I just stupid or som'tin'?

In my own effort, I tried to attach a literal control to a placeholder:
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>

void Page_Init(objec t sender,EventArg s e)
{
// Add a event Handler for 'Init'.
// myControl.Init += new System.EventHan dler(Control_In it);
PlaceHolder plc_hldr = (PlaceHolder) FindControl
("Dyn_Control_P laceholder");
plc_hldr.Init += new System.EventHan dler (plc_hldr_Contr ol_Init);
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void plc_hldr_Contro l_Init (object sender,EventArg s e)
{
Label lbl_msg01 = (Label) FindControl ("Message01" );

Dyn_Control_Pla ceholder.Contro ls.Add
( new LiteralControl( "<br>added 1 on init<br>") );
PlaceHolder plc_hldr = (PlaceHolder) FindControl
("Dyn_Control_P laceholder");

lbl_msg01.Text = "The ID of the object initially : " + plc_hldr.ID;
Response.Write( "The ID of the object initially : " + plc_hldr.ID);

plc_hldr.Contro ls.Add ( new LiteralControl( "<br>added 2 on
init<br>") );
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>



"wASP" <wylbur[at]ev1[dot]net> wrote in message
news:i8***** *************** ************@4a x.com...
On Thu, 28 Jul 2005 14:16:18 -0400, "Marina" <so*****@nospam .com> wrote:

>This is an example of dynamically adding an event handler to a control.
>They
>are assuming the control is already there.

Hi Marina,

OK - so I'm trying to add a handler to a control that has yet to be
instantiated?

Can you give me a clue as to how would I add a dynamic control
to a placeholder before Page_Load gets fired and the viewstate
is recovered on postback?

... or ...

How could I save the viewstate for a specific control (created
dynamically)
then recover it on Page_Load? ... THAT is a more important question.
Do you know of any good docs/books that might spell it out for a fool
like
myself?

I'm a newbie on this - and I've got a lot to learn.

- wASP


- wASP


- wASP
Nov 17 '05 #8
On Thu, 28 Jul 2005 21:49:59 +0200, "Wessel Troost" <no*****@like.t he.sun> wrote:
PlaceHolder plc_hldr = (PlaceHolder) FindControl
("Dyn_Control_P laceholder");
plc_hldr.Init += new System.EventHan dler(plc_hldr_C ontrol_Init);
You can replace that with:

Dyn_Control_Pla ceholder.Init += new
System.EventHa ndler(plc_hldr_ Control_Init);

Elements on the page are accessible by their ID.


I just tried replacing my FindControl with this - it didn't do any good
- same (non)result.

I don't understand why your plc_hldr_Contro l_Init isn't called though. I
tried a very simple sample, with this code:

void Page_Init(objec t sender, EventArgs e)
{
myControl.Init += new System.EventHan dler(Control_In it);
}

void Control_Init(ob ject sender, EventArgs e)
{
Response.Write( "Control_In it called);
}

I could break on the Page_Init() function, but the breakpoint in
Control_Init () never went off. Perhaps someone else has a clue ?

Greetings,
Wessel


THAT is not good - not good at all. :-(

Can you try it with my code?
This is the only change from the code in my first post:
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void Page_Init(objec t sender,EventArg s e)
{
// Add a event Handler for 'Init'.
Dyn_Control_Pla ceholder.Init
+= new System.EventHan dler (plc_hldr_Contr ol_Init);
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
void plc_hldr_Contro l_Init (object sender,EventArg s e)
{
Label lbl_msg01 = (Label) FindControl ("Message01" );

// Dyn_Control_Pla ceholder.Contro ls.Add
this.Controls.A dd
( new LiteralControl ("<br>added 1 on init<br>") );
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ *

Maybe it's time I started thinking about getting an IDE - Studio perhaps?

Does anyone have any suggestions?

- wASP
Nov 17 '05 #9

OK.

It seems to me that the only reason why I would want to create dynamic controls
in the initialization stage (Page_Init) would be to maintain viewstate.

If I were to save the viewstates for the dynamic controls by overriding
the functions with my own, then I could load everything during the Page_Load event
- and THEN load the viewstates for those controls at that time of the cycle
- and just sidestep the whole Page_Init problem entirely.

I've been reviewing the docs, and these are the given examples for those controls:
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>

Example

The following example overrides the SaveViewState method in a custom ASP.NET server
control.
When this method is invoked, it determines whether the control has any child controls
and whether the containing Page object is the result of a postback. If both are true,
it changes the Text property of a Label Web server control to read Custom Control Has
Saved State. It then saves the view state of the control as an array of objects,
named allStates.

protected override object SaveViewState()
{ // Change Text Property of Label when this function is invoked.
if(HasControls( ) && (Page.IsPostBac k))
{
((Label)(Contro ls[0])).Text = "Custom Control Has Saved State";
}
// Save State as a cumulative array of objects.
object baseState = base.SaveViewSt ate();
string userText = UserText;
string passwordText = PasswordText;
object[] allStates = new object[3];
allStates[0] = baseState;
allStates[1] = userText;
allStates[2] = PasswordText;
return allStates;
}

<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>

I can follow that, but what do I do about non-textual controls?
... such as radio buttons?

Would I have to design my own logic to recover the states for those?

That isn't an insurmountable problem (I don't think), but if there is
already a mechanism for doing this, then I wouldn't have to bother.

Do all of the elements in the "allStates" object have to be strings?
... or can I give it ANY type?

I'm thinking that the data stored within that viewstate object
would be in the same direct binary format as it is presented by the control
- as would have to be the case for the recovery of ALL viewstates
- whether it's done automatically or by explicit invocation.

OK - and here's where I need experienced input and perspective ...

Are there any potential pitfalls that I should be aware of in taking this course?

I have a feeling that this isn't going to be as simple as I think it might be.

This is the given example for the LoadViewState method:
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>

Example

The following example overrides the LoadViewState method for a custom ASP.NET
server control. It creates an Object array to contain the view state information
passed in the savedState parameter, and then calls the base implementation of
the LoadViewState method for the first index location of the array. It assigns
the values stored at the next two index locations to variables named UserText
and PasswordText, respectively.

protected override void LoadViewState(o bject savedState)
{
if (savedState != null)
{
// Load State from the array of objects that was saved at ;
// SavedViewState.
object[] myState = (object[])savedState;
if (myState[0] != null)
base.LoadViewSt ate(myState[0]);
if (myState[1] != null)
UserText = (string)myState[1];
if (myState[2] != null)
PasswordText = (string)myState[2];
}
}
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>-<[+]>
- wASP
Nov 17 '05 #10

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

Similar topics

6
4479
by: Mark | last post by:
I have been working for quite some time on this issue which in theory should be quite simple. The problem is that the Cancel and Save events are not fired when their respective buttons are clicked. I have read several posts which say to put your column generating section in the Page_Init section and it will solve the problem....however, it hasn't solved mine. Can somebody please take a look at this and provide any insight if possible?
4
7235
by: Tom Wisnowski | last post by:
Hello all, Here is a simple example of what I'm doing... Create a ASPX page Add a PlaceHolder(plch) and a Button(btn) to the page. In the code behind on Page_load add the following... TextBox txt = new TextBox(); if(!IsPostBack)
4
6730
by: Chuck Ritzke | last post by:
Hi, I've searched the newsgroup and other sources to understand how to handle runtime controls and see I'm not the only one who's confused, but I'm still not quite sure of the best way to handle from all the various explanations/answers. I'm attempting the typical scenario... I create a variable number of controls at runtime based on parameters from a database.
3
3985
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which step you're on. This all works fine, but I ran into some trouble when I started creating controls dynamically in my code-behind file. Each panel contains a table which is filled with various radio buttons, text fields and the such which are...
0
1514
by: Phl | last post by:
Hi, I am trying to create an webform which loads usercontrols dyanamically. I know exactly what to load for some of these controls but for some, I dont want to load it until the user has press a button. The controls which I know I will need at page init gets their viewstate contents back properly per postback. However I am having a lot of troubles with keeping the contents of usercontrols which are
0
2292
by: jonelling | last post by:
I am having a problem where the page load event is not being fired for certain user controls that I load dynamically in placeholders. Here is what I'm doing in brief, with full test code supplied at the bottom. In my controlling .aspx page, in the page_init() sub, if not postback, I load two user controls and place them in placeholders. This works and a trace statement in each user control's page load handler is executed on initial...
13
10185
by: rn5a | last post by:
In a shopping cart app, suppose a user has placed 5 orders, I want to show him 5 LinkButtons (one for each order) so that when he clicks the first LinkButton, he would be shown the details of his first order. Likewise if he clicks the second LinkButton, he will be shown the details of the second order he had placed. The Text of the LinkButtons will be 1 2 3 etc. So this user would see 1 2 3 4 5 as the LinkButtons. The problem is...
2
1333
by: BillE | last post by:
I have a web form which has dynamic controls for order entry, (item selected, #,etc.) which are wired to an event handler which fires when the dynamic controls content changes. These controls have to be recreated on the Page_Init for the events to fire. The content of the controls is based on the current CustomerID, and the order data entered is linked to the customerID. If the user selects a customer, the customer ID needs to be...
4
51672
Frinavale
by: Frinavale | last post by:
Introduction Sometimes, when developing web applications, we need to be able to dynamically load controls based on user selections. The following article describes a simple scenario where TextBox controls need to be dynamically loaded according to user input. This simple example can be further extended to dynamically load custom web user controls. Background Please familiarize yourself with the ASP.NET Page Life Cycle. It is crucial to...
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10267
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...
1
10046
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
9915
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
8939
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...
0
5358
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4014
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
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.