By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,480 Members | 767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,480 IT Pros & Developers. It's quick & easy.

Changing Text property on label from dynamic imagebutton

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
"Henke" <fu**********@hetmail.com> wrote in message
news:OX**************@TK2MSFTNGP09.phx.gbl...
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

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.