473,545 Members | 1,310 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Maintaining the look of dynamically added usercontrols

I have a page which I dynamically add several usercontrols (*.ascx files) to
using the following code:
Public Sub Refresh()
For Each section As DataRow In Me.GetSections( ).Rows
CType(Me.FindCo ntrol("admin" & CStr(section("b uttontext")).Re place(" ",
"")), adminsection2). RefreshSection( )
Next
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Dim sections As DataTable = Me.GetSections( )
For Each section As DataRow In sections.Rows
Me.AddAdminSect ion(CStr(sectio n("buttontext") ))
Next
Me.Refresh()
End Sub

Private Function GetSections() As DataTable
Dim sections As New DataTable
Dim dataadapterSele ct As New OleDbDataAdapte r("SELECT buttontext FROM
subnavigation WHERE buttontext<>'Mo re.' AND category='" &
Request.QuerySt ring("category" ) & "' ORDER BY buttonorder",
System.Configur ation.Configura tionManager.App Settings("conne ctionstring"))
dataadapterSele ct.Fill(section s)
Return sections
End Function

Private Sub AddAdminSection (ByVal section As String)
Dim admin As adminsection2 =
CType(Page.Load Control("~/usercontrols/adminsection2.a scx"), adminsection2)
admin.ID = "admin" & section.Replace (" ", "")
admin.Section = section
Me.form1.Contro ls.Add(admin)
End Sub
My problem is that the controls are reloaded every time, as you can see from
the Load event. If I place the following line

Me.AddAdminSect ion(CStr(sectio n("buttontext") ))

in an If Not Me.IsPostBack() statement, then it is only loaded the first
time and I recieve an object does not exist error every time the Refresh()
method is called (which is reasonably often, because this is for an
administration page where the user edits DB records). What can I do to
maintain the look of the dynamically added controls (in other words, how can
I avoid replacing them with every postback)? If there is any other code you
need to see that might help, let me know. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
Jun 16 '07 #1
7 2122
On Jun 16, 10:53 am, "Nathan Sokalski" <njsokal...@hot mail.comwrote:
I have a page which I dynamically add several usercontrols (*.ascx files) to
using the following code:

Public Sub Refresh()
For Each section As DataRow In Me.GetSections( ).Rows
CType(Me.FindCo ntrol("admin" & CStr(section("b uttontext")).Re place(" ",
"")), adminsection2). RefreshSection( )
Next
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Dim sections As DataTable = Me.GetSections( )
For Each section As DataRow In sections.Rows
Me.AddAdminSect ion(CStr(sectio n("buttontext") ))
Next
Me.Refresh()
End Sub

Private Function GetSections() As DataTable
Dim sections As New DataTable
Dim dataadapterSele ct As New OleDbDataAdapte r("SELECT buttontext FROM
subnavigation WHERE buttontext<>'Mo re.' AND category='" &
Request.QuerySt ring("category" ) & "' ORDER BY buttonorder",
System.Configur ation.Configura tionManager.App Settings("conne ctionstring"))
dataadapterSele ct.Fill(section s)
Return sections
End Function

Private Sub AddAdminSection (ByVal section As String)
Dim admin As adminsection2 =
CType(Page.Load Control("~/usercontrols/adminsection2.a scx"), adminsection2)
admin.ID = "admin" & section.Replace (" ", "")
admin.Section = section
Me.form1.Contro ls.Add(admin)
End Sub

My problem is that the controls are reloaded every time, as you can see from
the Load event. If I place the following line

Me.AddAdminSect ion(CStr(sectio n("buttontext") ))

in an If Not Me.IsPostBack() statement, then it is only loaded the first
time and I recieve an object does not exist error every time the Refresh()
method is called (which is reasonably often, because this is for an
administration page where the user edits DB records). What can I do to
maintain the look of the dynamically added controls (in other words, how can
I avoid replacing them with every postback)? If there is any other code you
need to see that might help, let me know. Thanks.
--
Nathan Sokalski
njsokal...@hotm ail.comhttp://www.nathansokal ski.com/
Hi,

Dynamically loaded controls need to be load after each post back...
other wise dynamically loaded control's event wont work...
Its always a good practice to load the controls in page_init event

Thanks
Masudur

Jun 16 '07 #2
Isn't there any kind of workaround? I am sure that I am not the first person
to want to maintain the properties of dynamically loaded usercontrols
between postbacks. Anybody have any ideas? Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Masudur" <mu*****@gmail. comwrote in message
news:11******** *************@o 11g2000prd.goog legroups.com...
On Jun 16, 10:53 am, "Nathan Sokalski" <njsokal...@hot mail.comwrote:
>I have a page which I dynamically add several usercontrols (*.ascx files)
to
using the following code:

Public Sub Refresh()
For Each section As DataRow In Me.GetSections( ).Rows
CType(Me.FindCo ntrol("admin" & CStr(section("b uttontext")).Re place("
",
"")), adminsection2). RefreshSection( )
Next
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventAr gs) Handles Me.Load
Dim sections As DataTable = Me.GetSections( )
For Each section As DataRow In sections.Rows
Me.AddAdminSect ion(CStr(sectio n("buttontext") ))
Next
Me.Refresh()
End Sub

Private Function GetSections() As DataTable
Dim sections As New DataTable
Dim dataadapterSele ct As New OleDbDataAdapte r("SELECT buttontext FROM
subnavigatio n WHERE buttontext<>'Mo re.' AND category='" &
Request.QueryS tring("category ") & "' ORDER BY buttonorder",
System.Configu ration.Configur ationManager.Ap pSettings("conn ectionstring"))
dataadapterSele ct.Fill(section s)
Return sections
End Function

Private Sub AddAdminSection (ByVal section As String)
Dim admin As adminsection2 =
CType(Page.Loa dControl("~/usercontrols/adminsection2.a scx"),
adminsection 2)
admin.ID = "admin" & section.Replace (" ", "")
admin.Section = section
Me.form1.Contro ls.Add(admin)
End Sub

My problem is that the controls are reloaded every time, as you can see
from
the Load event. If I place the following line

Me.AddAdminSec tion(CStr(secti on("buttontext" )))

in an If Not Me.IsPostBack() statement, then it is only loaded the first
time and I recieve an object does not exist error every time the
Refresh()
method is called (which is reasonably often, because this is for an
administrati on page where the user edits DB records). What can I do to
maintain the look of the dynamically added controls (in other words, how
can
I avoid replacing them with every postback)? If there is any other code
you
need to see that might help, let me know. Thanks.
--
Nathan Sokalski
njsokal...@hot mail.comhttp://www.nathansokal ski.com/

Hi,

Dynamically loaded controls need to be load after each post back...
other wise dynamically loaded control's event wont work...
Its always a good practice to load the controls in page_init event

Thanks
Masudur

Jun 17 '07 #3
Nathan,

Probably Ajax, however I am seriously curious what a usercontrol for ASPNET
has to do with ADONET.

Cor

"Nathan Sokalski" <nj********@hot mail.comschreef in bericht
news:eT******** ******@TK2MSFTN GP05.phx.gbl...
Isn't there any kind of workaround? I am sure that I am not the first
person to want to maintain the properties of dynamically loaded
usercontrols between postbacks. Anybody have any ideas? Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Masudur" <mu*****@gmail. comwrote in message
news:11******** *************@o 11g2000prd.goog legroups.com...
>On Jun 16, 10:53 am, "Nathan Sokalski" <njsokal...@hot mail.comwrote:
>>I have a page which I dynamically add several usercontrols (*.ascx
files) to
using the following code:

Public Sub Refresh()
For Each section As DataRow In Me.GetSections( ).Rows
CType(Me.FindCo ntrol("admin" & CStr(section("b uttontext")).Re place("
",
"")), adminsection2). RefreshSection( )
Next
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventA rgs) Handles Me.Load
Dim sections As DataTable = Me.GetSections( )
For Each section As DataRow In sections.Rows
Me.AddAdminSect ion(CStr(sectio n("buttontext") ))
Next
Me.Refresh()
End Sub

Private Function GetSections() As DataTable
Dim sections As New DataTable
Dim dataadapterSele ct As New OleDbDataAdapte r("SELECT buttontext FROM
subnavigati on WHERE buttontext<>'Mo re.' AND category='" &
Request.Query String("categor y") & "' ORDER BY buttonorder",
System.Config uration.Configu rationManager.A ppSettings("con nectionstring") )
dataadapterSele ct.Fill(section s)
Return sections
End Function

Private Sub AddAdminSection (ByVal section As String)
Dim admin As adminsection2 =
CType(Page.Lo adControl("~/usercontrols/adminsection2.a scx"),
adminsection2 )
admin.ID = "admin" & section.Replace (" ", "")
admin.Section = section
Me.form1.Contro ls.Add(admin)
End Sub

My problem is that the controls are reloaded every time, as you can see
from
the Load event. If I place the following line

Me.AddAdminSe ction(CStr(sect ion("buttontext ")))

in an If Not Me.IsPostBack() statement, then it is only loaded the first
time and I recieve an object does not exist error every time the
Refresh()
method is called (which is reasonably often, because this is for an
administratio n page where the user edits DB records). What can I do to
maintain the look of the dynamically added controls (in other words, how
can
I avoid replacing them with every postback)? If there is any other code
you
need to see that might help, let me know. Thanks.
--
Nathan Sokalski
njsokal...@ho tmail.comhttp://www.nathansokal ski.com/

Hi,

Dynamically loaded controls need to be load after each post back...
other wise dynamically loaded control's event wont work...
Its always a good practice to load the controls in page_init event

Thanks
Masudur


Jun 18 '07 #4

"Nathan Sokalski" <nj********@hot mail.comwrote in message
news:eT******** ******@TK2MSFTN GP05.phx.gbl...
Isn't there any kind of workaround? I am sure that I am not the first
person to want to maintain the properties of dynamically loaded
usercontrols between postbacks. Anybody have any ideas? Thanks.
You have to load dynamically added controls each time. Their properties are
mantained as with static controls.
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Jun 18 '07 #5
The dynamically added usercontrols that I want to maintain the look of
contain AJAX, and the reason for the postbacks is to update the data
accessed using ADO.NET, so there are your relations to AJAX and ADO.NET. The
main tags in the usercontrol are the following:

<asp:Panel>
<asp:Label/>
</asp:Panel>
<asp:Panel>
<asp:DataList >
</asp:DataList>
</asp:Panel>
<AJAX:Collapsib lePanelExtender/>

(obviously the controls all have their properties, and the DataList has it's
ItemTemplate and EditItemTemplat e). The property that I am having trouble
maintaining is the Collapsed property of the CollapsiblePane lExtender
control. The postbacks are usually caused by eventbubbling through Button
controls in the DataList. I haven't tried it yet, but one idea I thought
about was to put the DataList inside an UpdatePanel. The only concerns I had
with this idea were:

1. In some cases, a record is moved from the DataSource of one DataList to
the DataSource of another DataList. This would mean I would still need a way
to update all the DataLists regardless. Any ideas to make this possibility
work?

2. There is one section that on the page (not in the usercontrols, but on
the page that contains the usercontrols) that is used to add records,
obviously causing a postback. This would cause pretty much the same
situation as Concern #1, and would probably be solved in a similar way. Any
ideas for this?

The code I currently use to update the usercontrols is the following. The
*.ascx.vb file contains the following method, which is called for all of the
usercontrols from a method in the containing page (I removed the
OleDbDataAdapte r's SQL to keep the code short in the posting):

Public Sub RefreshSection( )
Dim sectiontable As New DataTable
Dim sectionadapter As New OleDbDataAdapte r("",
ConfigurationMa nager.AppSettin gs("connections tring"))
sectionadapter. Fill(sectiontab le)
Me.datSection.D ataSource = sectiontable
Me.datSection.D ataBind()
End Sub

Do any of these ideas or information help give a way to solve my problem?
Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
Nathan,

Probably Ajax, however I am seriously curious what a usercontrol for
ASPNET has to do with ADONET.

Cor

"Nathan Sokalski" <nj********@hot mail.comschreef in bericht
news:eT******** ******@TK2MSFTN GP05.phx.gbl...
>Isn't there any kind of workaround? I am sure that I am not the first
person to want to maintain the properties of dynamically loaded
usercontrols between postbacks. Anybody have any ideas? Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Masudur" <mu*****@gmail. comwrote in message
news:11******* **************@ o11g2000prd.goo glegroups.com.. .
>>On Jun 16, 10:53 am, "Nathan Sokalski" <njsokal...@hot mail.comwrote:
I have a page which I dynamically add several usercontrols (*.ascx
files) to
using the following code:

Public Sub Refresh()
For Each section As DataRow In Me.GetSections( ).Rows
CType(Me.FindCo ntrol("admin" & CStr(section("b uttontext")).Re place("
",
"")), adminsection2). RefreshSection( )
Next
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.Event Args) Handles Me.Load
Dim sections As DataTable = Me.GetSections( )
For Each section As DataRow In sections.Rows
Me.AddAdminSect ion(CStr(sectio n("buttontext") ))
Next
Me.Refresh()
End Sub

Private Function GetSections() As DataTable
Dim sections As New DataTable
Dim dataadapterSele ct As New OleDbDataAdapte r("SELECT buttontext FROM
subnavigatio n WHERE buttontext<>'Mo re.' AND category='" &
Request.Quer yString("catego ry") & "' ORDER BY buttonorder",
System.Confi guration.Config urationManager. AppSettings("co nnectionstring" ))
dataadapterSele ct.Fill(section s)
Return sections
End Function

Private Sub AddAdminSection (ByVal section As String)
Dim admin As adminsection2 =
CType(Page.L oadControl("~/usercontrols/adminsection2.a scx"),
adminsection 2)
admin.ID = "admin" & section.Replace (" ", "")
admin.Section = section
Me.form1.Contro ls.Add(admin)
End Sub

My problem is that the controls are reloaded every time, as you can see
from
the Load event. If I place the following line

Me.AddAdminS ection(CStr(sec tion("buttontex t")))

in an If Not Me.IsPostBack() statement, then it is only loaded the
first
time and I recieve an object does not exist error every time the
Refresh()
method is called (which is reasonably often, because this is for an
administrati on page where the user edits DB records). What can I do to
maintain the look of the dynamically added controls (in other words,
how can
I avoid replacing them with every postback)? If there is any other code
you
need to see that might help, let me know. Thanks.
--
Nathan Sokalski
njsokal...@h otmail.comhttp://www.nathansokal ski.com/

Hi,

Dynamically loaded controls need to be load after each post back...
other wise dynamically loaded control's event wont work...
Its always a good practice to load the controls in page_init event

Thanks
Masudur



Jun 18 '07 #6
Nathan,

We have used that on our VB-Tips website, however I have not enough time to
get a nice sample from that. Why don't you make for your self a simple
sample only containing your problem.

You will find that you than find the solution.

Cor

"Nathan Sokalski" <nj********@hot mail.comschreef in bericht
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
The dynamically added usercontrols that I want to maintain the look of
contain AJAX, and the reason for the postbacks is to update the data
accessed using ADO.NET, so there are your relations to AJAX and ADO.NET.
The main tags in the usercontrol are the following:

<asp:Panel>
<asp:Label/>
</asp:Panel>
<asp:Panel>
<asp:DataList >
</asp:DataList>
</asp:Panel>
<AJAX:Collapsib lePanelExtender/>

(obviously the controls all have their properties, and the DataList has
it's ItemTemplate and EditItemTemplat e). The property that I am having
trouble maintaining is the Collapsed property of the
CollapsiblePane lExtender control. The postbacks are usually caused by
eventbubbling through Button controls in the DataList. I haven't tried it
yet, but one idea I thought about was to put the DataList inside an
UpdatePanel. The only concerns I had with this idea were:

1. In some cases, a record is moved from the DataSource of one DataList to
the DataSource of another DataList. This would mean I would still need a
way to update all the DataLists regardless. Any ideas to make this
possibility work?

2. There is one section that on the page (not in the usercontrols, but on
the page that contains the usercontrols) that is used to add records,
obviously causing a postback. This would cause pretty much the same
situation as Concern #1, and would probably be solved in a similar way.
Any ideas for this?

The code I currently use to update the usercontrols is the following. The
*.ascx.vb file contains the following method, which is called for all of
the usercontrols from a method in the containing page (I removed the
OleDbDataAdapte r's SQL to keep the code short in the posting):

Public Sub RefreshSection( )
Dim sectiontable As New DataTable
Dim sectionadapter As New OleDbDataAdapte r("",
ConfigurationMa nager.AppSettin gs("connections tring"))
sectionadapter. Fill(sectiontab le)
Me.datSection.D ataSource = sectiontable
Me.datSection.D ataBind()
End Sub

Do any of these ideas or information help give a way to solve my problem?
Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>Nathan,

Probably Ajax, however I am seriously curious what a usercontrol for
ASPNET has to do with ADONET.

Cor

"Nathan Sokalski" <nj********@hot mail.comschreef in bericht
news:eT******* *******@TK2MSFT NGP05.phx.gbl.. .
>>Isn't there any kind of workaround? I am sure that I am not the first
person to want to maintain the properties of dynamically loaded
usercontrol s between postbacks. Anybody have any ideas? Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Masudur" <mu*****@gmail. comwrote in message
news:11****** *************** @o11g2000prd.go oglegroups.com. ..
On Jun 16, 10:53 am, "Nathan Sokalski" <njsokal...@hot mail.comwrote:
I have a page which I dynamically add several usercontrols (*.ascx
files) to
using the following code:
>
Public Sub Refresh()
For Each section As DataRow In Me.GetSections( ).Rows
CType(Me.FindCo ntrol("admin" &
CStr(sectio n("buttontext") ).Replace(" ",
"")), adminsection2). RefreshSection( )
Next
End Sub
>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.Even tArgs) Handles Me.Load
Dim sections As DataTable = Me.GetSections( )
For Each section As DataRow In sections.Rows
Me.AddAdminSect ion(CStr(sectio n("buttontext") ))
Next
Me.Refresh()
End Sub
>
Private Function GetSections() As DataTable
Dim sections As New DataTable
Dim dataadapterSele ct As New OleDbDataAdapte r("SELECT buttontext
FROM
subnavigati on WHERE buttontext<>'Mo re.' AND category='" &
Request.Que ryString("categ ory") & "' ORDER BY buttonorder",
System.Conf iguration.Confi gurationManager .AppSettings("c onnectionstring "))
dataadapterSele ct.Fill(section s)
Return sections
End Function
>
Private Sub AddAdminSection (ByVal section As String)
Dim admin As adminsection2 =
CType(Page. LoadControl("~/usercontrols/adminsection2.a scx"),
adminsectio n2)
admin.ID = "admin" & section.Replace (" ", "")
admin.Section = section
Me.form1.Contro ls.Add(admin)
End Sub
>
My problem is that the controls are reloaded every time, as you can
see from
the Load event. If I place the following line
>
Me.AddAdmin Section(CStr(se ction("buttonte xt")))
>
in an If Not Me.IsPostBack() statement, then it is only loaded the
first
time and I recieve an object does not exist error every time the
Refresh()
method is called (which is reasonably often, because this is for an
administrat ion page where the user edits DB records). What can I do to
maintain the look of the dynamically added controls (in other words,
how can
I avoid replacing them with every postback)? If there is any other
code you
need to see that might help, let me know. Thanks.
--
Nathan Sokalski
njsokal...@ hotmail.comhttp ://www.nathansokal ski.com/

Hi,

Dynamicall y loaded controls need to be load after each post back...
other wise dynamically loaded control's event wont work...
Its always a good practice to load the controls in page_init event

Thanks
Masudur



Jun 19 '07 #7
If it was now friday I could make the sample.
"Nathan Sokalski" <nj********@hot mail.comschreef in bericht
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
The dynamically added usercontrols that I want to maintain the look of
contain AJAX, and the reason for the postbacks is to update the data
accessed using ADO.NET, so there are your relations to AJAX and ADO.NET.
The main tags in the usercontrol are the following:

<asp:Panel>
<asp:Label/>
</asp:Panel>
<asp:Panel>
<asp:DataList >
</asp:DataList>
</asp:Panel>
<AJAX:Collapsib lePanelExtender/>

(obviously the controls all have their properties, and the DataList has
it's ItemTemplate and EditItemTemplat e). The property that I am having
trouble maintaining is the Collapsed property of the
CollapsiblePane lExtender control. The postbacks are usually caused by
eventbubbling through Button controls in the DataList. I haven't tried it
yet, but one idea I thought about was to put the DataList inside an
UpdatePanel. The only concerns I had with this idea were:

1. In some cases, a record is moved from the DataSource of one DataList to
the DataSource of another DataList. This would mean I would still need a
way to update all the DataLists regardless. Any ideas to make this
possibility work?

2. There is one section that on the page (not in the usercontrols, but on
the page that contains the usercontrols) that is used to add records,
obviously causing a postback. This would cause pretty much the same
situation as Concern #1, and would probably be solved in a similar way.
Any ideas for this?

The code I currently use to update the usercontrols is the following. The
*.ascx.vb file contains the following method, which is called for all of
the usercontrols from a method in the containing page (I removed the
OleDbDataAdapte r's SQL to keep the code short in the posting):

Public Sub RefreshSection( )
Dim sectiontable As New DataTable
Dim sectionadapter As New OleDbDataAdapte r("",
ConfigurationMa nager.AppSettin gs("connections tring"))
sectionadapter. Fill(sectiontab le)
Me.datSection.D ataSource = sectiontable
Me.datSection.D ataBind()
End Sub

Do any of these ideas or information help give a way to solve my problem?
Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>Nathan,

Probably Ajax, however I am seriously curious what a usercontrol for
ASPNET has to do with ADONET.

Cor

"Nathan Sokalski" <nj********@hot mail.comschreef in bericht
news:eT******* *******@TK2MSFT NGP05.phx.gbl.. .
>>Isn't there any kind of workaround? I am sure that I am not the first
person to want to maintain the properties of dynamically loaded
usercontrol s between postbacks. Anybody have any ideas? Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Masudur" <mu*****@gmail. comwrote in message
news:11****** *************** @o11g2000prd.go oglegroups.com. ..
On Jun 16, 10:53 am, "Nathan Sokalski" <njsokal...@hot mail.comwrote:
I have a page which I dynamically add several usercontrols (*.ascx
files) to
using the following code:
>
Public Sub Refresh()
For Each section As DataRow In Me.GetSections( ).Rows
CType(Me.FindCo ntrol("admin" &
CStr(sectio n("buttontext") ).Replace(" ",
"")), adminsection2). RefreshSection( )
Next
End Sub
>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.Even tArgs) Handles Me.Load
Dim sections As DataTable = Me.GetSections( )
For Each section As DataRow In sections.Rows
Me.AddAdminSect ion(CStr(sectio n("buttontext") ))
Next
Me.Refresh()
End Sub
>
Private Function GetSections() As DataTable
Dim sections As New DataTable
Dim dataadapterSele ct As New OleDbDataAdapte r("SELECT buttontext
FROM
subnavigati on WHERE buttontext<>'Mo re.' AND category='" &
Request.Que ryString("categ ory") & "' ORDER BY buttonorder",
System.Conf iguration.Confi gurationManager .AppSettings("c onnectionstring "))
dataadapterSele ct.Fill(section s)
Return sections
End Function
>
Private Sub AddAdminSection (ByVal section As String)
Dim admin As adminsection2 =
CType(Page. LoadControl("~/usercontrols/adminsection2.a scx"),
adminsectio n2)
admin.ID = "admin" & section.Replace (" ", "")
admin.Section = section
Me.form1.Contro ls.Add(admin)
End Sub
>
My problem is that the controls are reloaded every time, as you can
see from
the Load event. If I place the following line
>
Me.AddAdmin Section(CStr(se ction("buttonte xt")))
>
in an If Not Me.IsPostBack() statement, then it is only loaded the
first
time and I recieve an object does not exist error every time the
Refresh()
method is called (which is reasonably often, because this is for an
administrat ion page where the user edits DB records). What can I do to
maintain the look of the dynamically added controls (in other words,
how can
I avoid replacing them with every postback)? If there is any other
code you
need to see that might help, let me know. Thanks.
--
Nathan Sokalski
njsokal...@ hotmail.comhttp ://www.nathansokal ski.com/

Hi,

Dynamicall y loaded controls need to be load after each post back...
other wise dynamically loaded control's event wont work...
Its always a good practice to load the controls in page_init event

Thanks
Masudur



Jun 19 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1762
by: Earl Teigrob | last post by:
I am building a custom control that I want to server as a container for child controls that can be dynamically added to this control. I can persist the child controls that are added to my custom control but can to get them to retain view state. Below is a striped down version of my control. It exposes one property of type...
4
3097
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three UserControls into the PlaceHolder's child control collection depending upon which of the three radio buttons is selected. Each of the three UserControls have...
9
2437
by: Anders K. Jacobsen [DK] | last post by:
Hi I have this that adds some usercontrol (UCTodays.ascx) to a placeholder foreach(A a in B){ UCTodays ucline = (UCTodays )LoadControl("UCTodays.ascx"); ucline.Initializecontrol(line,alternate); Placeholder1.Controls.Add(ucline); }
7
3179
by: Samuel | last post by:
Hi, I am building a page that makes use of user control as a templating technique. The following is that I have in mind and it is actually working: Root/ -- login.aspx -- login.aspx.vb -- UC/ ----- Classic/
2
1700
by: Vivek Sharma | last post by:
Hi There, I have a situation where I wish to load the controls dynamically on the basis of user role. Hence, I am using this code. if (UserRole == "IS Administrator") { Control UC1 = LoadControl("../UserControls/ISJob/uctlJobGeneral.ascx");
2
2444
by: Pete Moss | last post by:
During a postback event, I am having trouble retrieving the state of a CheckBox Control that I am dynamically adding to a DataGrid Control using ASP.NET 1.1. I have no trouble adding the TemplateColumn dynamically. I persist a DataSet in my Session object and I bind the CheckBox to the DataSet. So far so good. The CheckBoxes show up and the...
3
3496
by: OJ | last post by:
Hi, I have added code to run on a button click event which adds usercontrols to an asp:Panel control held in a contentplaceholder defined by the masterpage. for (int x = 0; x < (Master.PartyCtrl.Adults ); x++) { ASP.usercontrols_passenger_ascx passenger = new ASP.usercontrols_passenger_ascx(); this.pnlAdults.Controls.Add(passenger);
7
2122
by: =?Utf-8?B?Li46OiBLZXZpbiA6Oi4u?= | last post by:
I have a problem with accessing controls that I have loaded dynamically and added to a web page. The scenario: I have a webpage that displays multiple instances of a user control on the page. The number of controls that are displayed can be adjusted by the user so the controls are added to the page dynamically using the following code in...
3
8195
by: JacekDr | last post by:
Hello, I've got the following problem: I want to add and remove dynamically controls to UpdatePanel. In my user control I have a button, but when I click it I get AsyncPostback and Event for ButtonClick in UserControl doesn't fire. <asp:ScriptManager ID="ScriptManager" EnableViewState="true" runat="server" EnablePageMethods="True" >
0
7457
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7391
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7410
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7746
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5962
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1869
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
693
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.