Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Changing Text property on label from dynamic imagebutton

Reply
Thread Tools

Changing Text property on label from dynamic imagebutton

 
 
Henke
Guest
Posts: n/a
 
      05-04-2004
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


 
Reply With Quote
 
 
 
 
Henke
Guest
Posts: n/a
 
      05-05-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dll config and web.config and Label Expressions (binding label text to dll config settings) CSharpner ASP .Net 0 04-09-2007 09:00 PM
Programmatically Change Text Property of Label in ItemTemplate in Datagrid Craig ASP .Net 1 10-09-2004 12:36 AM
How do I do to underline a character in the property text of Button or Label ? I have to manage the AccessKeys. THANX ALok Gupta via .NET 247 ASP .Net 2 08-09-2004 03:15 PM
Changing Label property Viktor Popov ASP .Net 3 07-26-2004 03:42 PM
Inherit from ImageButton, add text property MarkMurphy ASP .Net Web Controls 5 07-14-2004 03:40 PM



Advertisments