Changing Text property on label from dynamic imagebutton

H

Henke

Hello,

I have one ImageButton controls which I initialize in
Page_Load and declare on class level.

ImageButton save = new ImageButton();
save.ImageUrl = "save.gif"
save.Click += new ImageClickEventHandler(this.save_click);

This ImageButton is added to a dynamic table which is also
in initialized in Page_Load

if(!PostBack)
{
createTableHead(); //The head of the table
createTableEdit() //The body of the table
Session["table"] = tblGeneric // This is saved in session and is
read from the session in OnInit. All dynamic controls needs to be re-
// initialized
}

function void createTableHead()
{
tblGeneric = new Table() // Declared at class level
TableRow row = new TableRow()
TableCell cell = new TableCell()

cell.Controls.add(save);
row.Cells.Add(cell)
tblGeneric.Rows.Add(row)

// more code below, but only new rows and cells.
}

I have one Label which contain error messages during the save method.
The event method which is connceted to the ImageButton click event fires
correctly, but when I want to change the
Text property on the Label object then the change is not reflected on the
web page. If I debug
the event method I can verify that the Text property has changed, but the
text on the web page is not updated.

If I drop a new ImageButton on the web page and let VS.IDE make a
save_click() method, then the
Label Text property is updated and the change is visible on the web page.

What I find strange is that the event handler method fires correctly and I
can access the tabels rows and cells and
the controls in the cells aswell, but I can not update the text on the web
page.

Do I have to declare and initialize the ImageButton in another Page method
or what is going on ?

Regards,

// Henrik
 
H

Henke

Hello again,

I have got this to work now.
This is the correct code:

Page_Init (not Page_Load)

ImageButton save = new ImageButton();
save.ImageUrl = "save.gif"
save.Click += new ImageClickEventHandler(this.save_click);

tblGeneric = Session["table"];
tblGeneric.Rows[0].Cells[1].Control.Clear(); // a brutal way, I´ll
try something else when I have got time
tblGeneric.Rows[0].Cells[1].Control.Add(save);

In Page_Load

if(!PostBack)
{
createTableHead(); //The head of the table
createTableEdit() //The body of the table
Session["table"] = tblGeneric // This is saved in session and is
read from the session in OnInit. All dynamic controls needs to be
re-initialized
}

The thing that throw me off was that the save_Click method was called, but
the changes I did
didn´t apply on the webpage. Is there any explanation to that or is it "by
design" in the framework?

Regards,

// Henke
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top