Problems with Dinamic controls

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alessandro

    #1

    Problems with Dinamic controls

    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.EventArg s) Handles MyBase.Load
    Dim oImageButton As New System.Web.UI.W ebControls.Imag eButton()
    oImageButton.Cs sClass = "tab"
    oImageButton.ID = "test"
    oImageButton.Co mmandName = "test"
    oImageButton.Ca usesValidation = True
    oImageButton.En ableViewState = True
    PlaceHold.Contr ols.Add(oImage)
    end


  • Bjoern Wolfgardt

    #2
    Re: Problems with Dinamic controls

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

    This should help you:
    oImageButton.Cl ick += new System.EventHan dler(this.oImag eButton_Click);

    where oImageButton_Cl ick is a function like this:

    private void oImageButton_Cl ick(object sender, System.EventArg s e)
    {
    Do something...
    }

    Hope this helps

    Bjoern Wolfgardt

    "Alessandro " <gemini_two@hot mail.com> schrieb im Newsbeitrag
    news:#xiUpf2SDH A.2248@TK2MSFTN GP11.phx.gbl...[color=blue]
    > i want to create dinamicaly an image Button, but i'm not able to associate[/color]
    a[color=blue]
    > relative server command on click, any idea ?
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArg s) Handles MyBase.Load
    > Dim oImageButton As New System.Web.UI.W ebControls.Imag eButton()
    > oImageButton.Cs sClass = "tab"
    > oImageButton.ID = "test"
    > oImageButton.Co mmandName = "test"
    > oImageButton.Ca usesValidation = True
    > oImageButton.En ableViewState = True
    > PlaceHold.Contr ols.Add(oImage)
    > end
    >
    >[/color]


    Comment

    • Cristian Suazo

      #3
      Re: Problems with Dinamic controls

      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 " <gemini_two@hot mail.com> wrote in message
      news:%23xiUpf2S DHA.2248@TK2MSF TNGP11.phx.gbl. ..[color=blue]
      > i want to create dinamicaly an image Button, but i'm not able to associate[/color]
      a[color=blue]
      > relative server command on click, any idea ?
      >
      > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
      > System.EventArg s) Handles MyBase.Load
      > Dim oImageButton As New System.Web.UI.W ebControls.Imag eButton()
      > oImageButton.Cs sClass = "tab"
      > oImageButton.ID = "test"
      > oImageButton.Co mmandName = "test"
      > oImageButton.Ca usesValidation = True
      > oImageButton.En ableViewState = True
      > PlaceHold.Contr ols.Add(oImage)
      > end
      >
      >[/color]


      Comment

      Working...