Problems with Dinamic controls

Discussion in 'ASP .Net' started by Alessandro, Jul 16, 2003.

  1. Alessandro

    Alessandro Guest

    i want to create dinamicaly an image Button, but i'm not able to associate a
    relative server command on click, any idea ?

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    Dim oImageButton As New System.Web.UI.WebControls.ImageButton()
    oImageButton.CssClass = "tab"
    oImageButton.ID = "test"
    oImageButton.CommandName = "test"
    oImageButton.CausesValidation = True
    oImageButton.EnableViewState = True
    PlaceHold.Controls.Add(oImage)
    end
    Alessandro, Jul 16, 2003
    #1
    1. Advertising

  2. If I understand you, you are missing the click event.

    This should help you:
    oImageButton.Click += new System.EventHandler(this.oImageButton_Click);

    where oImageButton_Click is a function like this:

    private void oImageButton_Click(object sender, System.EventArgs e)
    {
    Do something...
    }

    Hope this helps

    Bjoern Wolfgardt

    "Alessandro" <> schrieb im Newsbeitrag
    news:#...
    > i want to create dinamicaly an image Button, but i'm not able to associate

    a
    > relative server command on click, any idea ?
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    > Dim oImageButton As New System.Web.UI.WebControls.ImageButton()
    > oImageButton.CssClass = "tab"
    > oImageButton.ID = "test"
    > oImageButton.CommandName = "test"
    > oImageButton.CausesValidation = True
    > oImageButton.EnableViewState = True
    > PlaceHold.Controls.Add(oImage)
    > end
    >
    >
    Bjoern Wolfgardt, Jul 16, 2003
    #2
    1. Advertising

  3. You should also create you button in the Page_Init event. If not, then the
    event will not be detected.

    The reason for this is that the viewstate for the control is loaded before
    the Page_Load so if you create the control in the page_load then what
    happens:
    1. the viewstate is loaded, the button is not found so no viewstate is
    loaded into it
    2. Button is loaded in the page_load
    2. because the viewstate was not loaded, the event will not be triggered.

    In the case that you load the button in the page_init this happens:
    1. Button is loaded in the page_init
    2. viewstate is loaded for the control is loaded
    3. the event on the button click is triggered.

    I hope this cleared things up...

    /Cristian


    "Alessandro" <> wrote in message
    news:%...
    > i want to create dinamicaly an image Button, but i'm not able to associate

    a
    > relative server command on click, any idea ?
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    > Dim oImageButton As New System.Web.UI.WebControls.ImageButton()
    > oImageButton.CssClass = "tab"
    > oImageButton.ID = "test"
    > oImageButton.CommandName = "test"
    > oImageButton.CausesValidation = True
    > oImageButton.EnableViewState = True
    > PlaceHold.Controls.Add(oImage)
    > end
    >
    >
    Cristian Suazo, Jul 16, 2003
    #3
    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. Damir

    Dinamic images

    Damir, May 6, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    374
    Damir
    May 6, 2005
  2. whois
    Replies:
    12
    Views:
    582
    Roedy Green
    Jun 22, 2004
  3. Novello

    dinamic classloader?

    Novello, Jul 1, 2005, in forum: Java
    Replies:
    3
    Views:
    335
    Chris Smith
    Jul 1, 2005
  4. Roberto Dias
    Replies:
    1
    Views:
    739
    Paolo Alexis Falcone
    Jun 30, 2004
  5. Morgan
    Replies:
    7
    Views:
    444
    CBFalconer
    Feb 7, 2004
Loading...

Share This Page