473,385 Members | 1,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Changing Text property on label from dynamic imagebutton

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
1 3325
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dude | last post by:
Below is the code - it is finding the control, and there is no error, just not assigning the text to the label <asp:DataList id="dlGoals" runat="server" onEditCommand="myListEditHandler"...
7
by: Ed West | last post by:
Hello, I have a simple form with some input boxes. After validation if one fails, then I would like to at the top of the page say something like "The following fields in red are required" and...
1
by: sekisho | last post by:
I'm dynamically adding a column of labels and a column of text boxes to a panel on a webform, based on data returned from an SQL query, which the user builds by selecting options from a few...
7
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and...
4
by: Siah | last post by:
Hi, I wanted to dynamically update pieces of my page in the following fashion. Look at the following html code: <span id='person_23_name'> Mike </span> <span id='person_28_name'> Siah </span>...
6
by: AMP | last post by:
Hello, I have an mdi program with a child form ("A") and another child ("B"). I want to change the text of a label on A by changing an item from a combobox on B. I can code the...
5
by: g6023 | last post by:
Hi All Newbie to C# I am afraid The array of panel dispays OK but I am having problems with accessing the controls within. My panels each have a number of label controls. How do I set, say,...
12
by: vbnewbie | last post by:
I am having problems accessing properties of dynamically generated objects in VB2005. Can someone please help? In a nutshell: My app creates an equal number of checkboxes and labels that share the...
1
by: ranger979 | last post by:
I am using the emptydatatemplate for a gridview control. I have a detailsview control within the emptydatatemplate. In the detailsview I have a templatefield that contains an imagebutton control...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.