Professional Web Applications Themes

Dynamically Loading User Control in PlaceHolder - ASP.NET Building Controls

Hi , I load dynamically a user control in PlaceHolder with the number of fileds in db. When loading user control there is no problem, if returning field number is 2 then 2 usr controls load in plcholder. But problem is that , after page postback plcholder says that I have no control, For i As Integer = 0 To plcHolderUsrCont.Controls.Count - 1 kontrol1 = DirectCast(plcHolderUsrCont.Controls(i), UrunGrupTeknik) Dim a As String = kontrol1.txtvalue Next I added a reference like below , because usr control loading dynamically <% Reference Control = "../kontroller/UrunGrupTeknik.ascx" %> I defined a protected variable that's type is ...

  1. #1

    Default Dynamically Loading User Control in PlaceHolder

    Hi ,
    I load dynamically a user control in PlaceHolder with the number of fileds
    in db.
    When loading user control there is no problem, if returning field number is
    2 then 2 usr controls load in plcholder.
    But problem is that , after page postback plcholder says that I have no
    control,

    For i As Integer = 0 To plcHolderUsrCont.Controls.Count - 1
    kontrol1 = DirectCast(plcHolderUsrCont.Controls(i),
    UrunGrupTeknik)
    Dim a As String = kontrol1.txtvalue
    Next

    I added a reference like below , because usr control loading dynamically
    <% Reference Control = "../kontroller/UrunGrupTeknik.ascx" %>

    I defined a protected variable that's type is my usr control
    Protected urunGrupTeknikTxtLbl As UrunGrupTeknik = New UrunGrupTeknik

    and I load user control like that..

    For i As Integer = 0 To tdsTeknikDetay.table1.Rows.Count - 1
    thisrowTeknikDetay = tdsTeknikDetay.table1.Rows(i)
    findControlPath = Request.ApplicationPath +
    "/kontroller/UrunGrupTeknik.ascx"
    kontrol1 = Me.LoadControl(findControlPath)
    urunGrupTeknikTxtLbl = DirectCast(kontrol1, UrunGrupTeknik)
    urunGrupTeknikTxtLbl.lblValue = thisrowTeknikDetay.ACIKLAMA
    kontrol1.ID = i
    plcHolderUsrCont.Controls.Add(kontrol1)
    Next

    plcHolder.controls.Count is set to 0 after postback:((
    Have you any idea about this problem ?

    Thnks....



    Ugur Ekinci Guest

  2. #2

    Default RE: Dynamically Loading User Control in PlaceHolder

    Hi,

    I have a asp table in my .aspx page. I dynamically add the control to this
    table. The page shows up fine. The control I had have 2 textboxes. Now I am
    stuck and not able to access any of these textboxes inside the control I
    added. Infact, i am not able to locate this control in the page.

    Please help me out.

    D. Santhosh

    "Ugur Ekinci" wrote:
    > Hi ,
    > I load dynamically a user control in PlaceHolder with the number of fileds
    > in db.
    > When loading user control there is no problem, if returning field number is
    > 2 then 2 usr controls load in plcholder.
    > But problem is that , after page postback plcholder says that I have no
    > control,
    >
    > For i As Integer = 0 To plcHolderUsrCont.Controls.Count - 1
    > kontrol1 = DirectCast(plcHolderUsrCont.Controls(i),
    > UrunGrupTeknik)
    > Dim a As String = kontrol1.txtvalue
    > Next
    >
    > I added a reference like below , because usr control loading dynamically
    > <% Reference Control = "../kontroller/UrunGrupTeknik.ascx" %>
    >
    > I defined a protected variable that's type is my usr control
    > Protected urunGrupTeknikTxtLbl As UrunGrupTeknik = New UrunGrupTeknik
    >
    > and I load user control like that..
    >
    > For i As Integer = 0 To tdsTeknikDetay.table1.Rows.Count - 1
    > thisrowTeknikDetay = tdsTeknikDetay.table1.Rows(i)
    > findControlPath = Request.ApplicationPath +
    > "/kontroller/UrunGrupTeknik.ascx"
    > kontrol1 = Me.LoadControl(findControlPath)
    > urunGrupTeknikTxtLbl = DirectCast(kontrol1, UrunGrupTeknik)
    > urunGrupTeknikTxtLbl.lblValue = thisrowTeknikDetay.ACIKLAMA
    > kontrol1.ID = i
    > plcHolderUsrCont.Controls.Add(kontrol1)
    > Next
    >
    > plcHolder.controls.Count is set to 0 after postback:((
    > Have you any idea about this problem ?
    >
    > Thnks....
    >
    >
    >
    >
    DS Guest

  3. #3

    Default Re: Dynamically Loading User Control in PlaceHolder

    This is a classic issue.

    ASP.NET will not persist your dynamically created controls by default, it
    will make sure the control-tree at the .aspx will be regenerated but thats
    all, no automatic support for your codebehind. They are simply won't be
    written to Viewstate tree, and hence corresponding server side control won't
    be re-created after a postback.

    You may use a helper control like this one instead of the PlaceHolder:
    [url]http://www.denisbauer.com/ASPNETControls/DynamicControlsPlaceholder.aspx[/url]

    Gokhan Altinoren
    gokhan[RMV_this][at]altinoren[also_RMV_this][dot]com
    [url]http://altinoren.com[/url]
    > Hi ,
    > I load dynamically a user control in PlaceHolder with the number of
    > fileds
    > in db.
    > When loading user control there is no problem, if returning field
    > number is
    > 2 then 2 usr controls load in plcholder.
    > But problem is that , after page postback plcholder says that I have
    > no
    > control,
    > For i As Integer = 0 To plcHolderUsrCont.Controls.Count - 1
    > kontrol1 = DirectCast(plcHolderUsrCont.Controls(i),
    > UrunGrupTeknik)
    > Dim a As String = kontrol1.txtvalue
    > Next
    > I added a reference like below , because usr control loading
    > dynamically <% Reference Control =
    > "../kontroller/UrunGrupTeknik.ascx" %>
    >
    > I defined a protected variable that's type is my usr control
    > Protected urunGrupTeknikTxtLbl As UrunGrupTeknik = New UrunGrupTeknik
    >
    > and I load user control like that..
    >
    > For i As Integer = 0 To tdsTeknikDetay.table1.Rows.Count - 1
    > thisrowTeknikDetay = tdsTeknikDetay.table1.Rows(i)
    > findControlPath = Request.ApplicationPath +
    > "/kontroller/UrunGrupTeknik.ascx"
    > kontrol1 = Me.LoadControl(findControlPath)
    > urunGrupTeknikTxtLbl = DirectCast(kontrol1,
    > UrunGrupTeknik)
    > urunGrupTeknikTxtLbl.lblValue =
    > thisrowTeknikDetay.ACIKLAMA
    > kontrol1.ID = i
    > plcHolderUsrCont.Controls.Add(kontrol1)
    > Next
    > plcHolder.controls.Count is set to 0 after postback:(( Have you any
    > idea about this problem ?
    >
    > Thnks....
    >

    Gokhan Altinoren Guest

Similar Threads

  1. Replies: 2
    Last Post: June 6th, 04:02 PM
  2. Dynamically loading user control
    By Divya in forum ASP.NET Building Controls
    Replies: 2
    Last Post: June 4th, 08:51 PM
  3. Dynamicly loaded User Control events in a Placeholder
    By MikeM in forum ASP.NET Building Controls
    Replies: 1
    Last Post: April 12th, 07:31 PM
  4. Removing a user control from within a placeholder
    By John in forum ASP.NET General
    Replies: 1
    Last Post: July 1st, 03:11 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139