Maintaining State

J

Jim Heavey

I have a placeholder control and in code I am adding a asp.net Table
control and a button control.

When I press the button (right now the event handler procedure only writes
a line to the Console) I make a round trip to the server, but the event
procedure is never executed. Also my table disappears even after I have
set the property to EnableViewState = true.

Why does my table not maitain state?
Why does my event procedure not execute?

Here is my code to set the event handler....

Button bntAddHighlightComment = new Button();
bntAddHighlightComment.Text = "Add Comment";
bntAddHighlightComment.Click += new System.EventHandler
(AddHighlightComments_Click);
plcDataEntry.Controls.Add(bntAddHighlightComment);

Here is my event handler code...

private void AddHighlightComments_Click(object sender, System.EventArgs e)
{
Console.WriteLine("Made it to button click event");
}


Thanks in advance for your assistance!!!!!!!!
 
M

Martin Dechev

Hi, Jim Heavey,

On every postback to the server the page object gets instantiated and what
you work with is the instance. If your controls are "static" (added to the
html part of the page) the parser does the job to instantiate the control
objects and add the references to the page object. If you decide to go for
the harder way (dynamically add the controls, that is) you must redo
everything on every postback - create the table, add it to the placeholder,
add the button, attach the event etc.

Hope this helps
Martin
 
G

Guest

It's the miracle of stateless programming...you'll grow to love it:

----- Jim Heavey wrote: ----

Boy, that bumbs me out...
 

Ask a Question

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

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

Ask a Question

Top