Changing Text property on label from dynamic imagebutton

Discussion in 'ASP .Net' started by Henke, May 4, 2004.

  1. Henke

    Henke Guest

    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
    Henke, May 4, 2004
    #1
    1. Advertising

  2. Henke

    Henke Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
    Henke, May 5, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Viktor Popov

    Changing Label property

    Viktor Popov, Jul 26, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    583
    clintonG
    Jul 26, 2004
  2. CSharpner
    Replies:
    0
    Views:
    1,000
    CSharpner
    Apr 9, 2007
  3. Dan
    Replies:
    2
    Views:
    434
  4. MarkMurphy

    Inherit from ImageButton, add text property

    MarkMurphy, Jul 6, 2004, in forum: ASP .Net Web Controls
    Replies:
    5
    Views:
    367
    MarkMurphy
    Jul 14, 2004
  5. Knut Krueger
    Replies:
    8
    Views:
    255
    Knut Krueger
    Aug 20, 2013
Loading...

Share This Page