473,322 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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.FindControl("admin" & CStr(section("buttontext")).Replace(" ",
"")), adminsection2).RefreshSection()
Next
End Sub

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

Private Function GetSections() As DataTable
Dim sections As New DataTable
Dim dataadapterSelect As New OleDbDataAdapter("SELECT buttontext FROM
subnavigation WHERE buttontext<>'More.' AND category='" &
Request.QueryString("category") & "' ORDER BY buttonorder",
System.Configuration.ConfigurationManager.AppSetti ngs("connectionstring"))
dataadapterSelect.Fill(sections)
Return sections
End Function

Private Sub AddAdminSection(ByVal section As String)
Dim admin As adminsection2 =
CType(Page.LoadControl("~/usercontrols/adminsection2.ascx"), adminsection2)
admin.ID = "admin" & section.Replace(" ", "")
admin.Section = section
Me.form1.Controls.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.AddAdminSection(CStr(section("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********@hotmail.com
http://www.nathansokalski.com/
Jun 16 '07 #1
7 2109
On Jun 16, 10:53 am, "Nathan Sokalski" <njsokal...@hotmail.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.FindControl("admin" & CStr(section("buttontext")).Replace(" ",
"")), adminsection2).RefreshSection()
Next
End Sub

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

Private Function GetSections() As DataTable
Dim sections As New DataTable
Dim dataadapterSelect As New OleDbDataAdapter("SELECT buttontext FROM
subnavigation WHERE buttontext<>'More.' AND category='" &
Request.QueryString("category") & "' ORDER BY buttonorder",
System.Configuration.ConfigurationManager.AppSetti ngs("connectionstring"))
dataadapterSelect.Fill(sections)
Return sections
End Function

Private Sub AddAdminSection(ByVal section As String)
Dim admin As adminsection2 =
CType(Page.LoadControl("~/usercontrols/adminsection2.ascx"), adminsection2)
admin.ID = "admin" & section.Replace(" ", "")
admin.Section = section
Me.form1.Controls.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.AddAdminSection(CStr(section("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...@hotmail.comhttp://www.nathansokalski.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********@hotmail.com
http://www.nathansokalski.com/

"Masudur" <mu*****@gmail.comwrote in message
news:11*********************@o11g2000prd.googlegro ups.com...
On Jun 16, 10:53 am, "Nathan Sokalski" <njsokal...@hotmail.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.FindControl("admin" & CStr(section("buttontext")).Replace("
",
"")), adminsection2).RefreshSection()
Next
End Sub

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

Private Function GetSections() As DataTable
Dim sections As New DataTable
Dim dataadapterSelect As New OleDbDataAdapter("SELECT buttontext FROM
subnavigation WHERE buttontext<>'More.' AND category='" &
Request.QueryString("category") & "' ORDER BY buttonorder",
System.Configuration.ConfigurationManager.AppSett ings("connectionstring"))
dataadapterSelect.Fill(sections)
Return sections
End Function

Private Sub AddAdminSection(ByVal section As String)
Dim admin As adminsection2 =
CType(Page.LoadControl("~/usercontrols/adminsection2.ascx"),
adminsection2)
admin.ID = "admin" & section.Replace(" ", "")
admin.Section = section
Me.form1.Controls.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.AddAdminSection(CStr(section("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...@hotmail.comhttp://www.nathansokalski.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********@hotmail.comschreef in bericht
news:eT**************@TK2MSFTNGP05.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********@hotmail.com
http://www.nathansokalski.com/

"Masudur" <mu*****@gmail.comwrote in message
news:11*********************@o11g2000prd.googlegro ups.com...
>On Jun 16, 10:53 am, "Nathan Sokalski" <njsokal...@hotmail.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.FindControl("admin" & CStr(section("buttontext")).Replace("
",
"")), adminsection2).RefreshSection()
Next
End Sub

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

Private Function GetSections() As DataTable
Dim sections As New DataTable
Dim dataadapterSelect As New OleDbDataAdapter("SELECT buttontext FROM
subnavigation WHERE buttontext<>'More.' AND category='" &
Request.QueryString("category") & "' ORDER BY buttonorder",
System.Configuration.ConfigurationManager.AppSet tings("connectionstring"))
dataadapterSelect.Fill(sections)
Return sections
End Function

Private Sub AddAdminSection(ByVal section As String)
Dim admin As adminsection2 =
CType(Page.LoadControl("~/usercontrols/adminsection2.ascx"),
adminsection2)
admin.ID = "admin" & section.Replace(" ", "")
admin.Section = section
Me.form1.Controls.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.AddAdminSection(CStr(section("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...@hotmail.comhttp://www.nathansokalski.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********@hotmail.comwrote in message
news:eT**************@TK2MSFTNGP05.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:CollapsiblePanelExtender/>

(obviously the controls all have their properties, and the DataList has it's
ItemTemplate and EditItemTemplate). The property that I am having trouble
maintaining is the Collapsed property of the CollapsiblePanelExtender
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
OleDbDataAdapter's SQL to keep the code short in the posting):

Public Sub RefreshSection()
Dim sectiontable As New DataTable
Dim sectionadapter As New OleDbDataAdapter("",
ConfigurationManager.AppSettings("connectionstring "))
sectionadapter.Fill(sectiontable)
Me.datSection.DataSource = sectiontable
Me.datSection.DataBind()
End Sub

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

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

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

Cor

"Nathan Sokalski" <nj********@hotmail.comschreef in bericht
news:eT**************@TK2MSFTNGP05.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********@hotmail.com
http://www.nathansokalski.com/

"Masudur" <mu*****@gmail.comwrote in message
news:11*********************@o11g2000prd.googlegr oups.com...
>>On Jun 16, 10:53 am, "Nathan Sokalski" <njsokal...@hotmail.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.FindControl("admin" & CStr(section("buttontext")).Replace("
",
"")), adminsection2).RefreshSection()
Next
End Sub

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

Private Function GetSections() As DataTable
Dim sections As New DataTable
Dim dataadapterSelect As New OleDbDataAdapter("SELECT buttontext FROM
subnavigation WHERE buttontext<>'More.' AND category='" &
Request.QueryString("category") & "' ORDER BY buttonorder",
System.Configuration.ConfigurationManager.AppSe ttings("connectionstring"))
dataadapterSelect.Fill(sections)
Return sections
End Function

Private Sub AddAdminSection(ByVal section As String)
Dim admin As adminsection2 =
CType(Page.LoadControl("~/usercontrols/adminsection2.ascx"),
adminsection2)
admin.ID = "admin" & section.Replace(" ", "")
admin.Section = section
Me.form1.Controls.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.AddAdminSection(CStr(section("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...@hotmail.comhttp://www.nathansokalski.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********@hotmail.comschreef in bericht
news:%2****************@TK2MSFTNGP02.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:CollapsiblePanelExtender/>

(obviously the controls all have their properties, and the DataList has
it's ItemTemplate and EditItemTemplate). The property that I am having
trouble maintaining is the Collapsed property of the
CollapsiblePanelExtender 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
OleDbDataAdapter's SQL to keep the code short in the posting):

Public Sub RefreshSection()
Dim sectiontable As New DataTable
Dim sectionadapter As New OleDbDataAdapter("",
ConfigurationManager.AppSettings("connectionstring "))
sectionadapter.Fill(sectiontable)
Me.datSection.DataSource = sectiontable
Me.datSection.DataBind()
End Sub

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

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

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

Cor

"Nathan Sokalski" <nj********@hotmail.comschreef in bericht
news:eT**************@TK2MSFTNGP05.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********@hotmail.com
http://www.nathansokalski.com/

"Masudur" <mu*****@gmail.comwrote in message
news:11*********************@o11g2000prd.googleg roups.com...
On Jun 16, 10:53 am, "Nathan Sokalski" <njsokal...@hotmail.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.FindControl("admin" &
CStr(section("buttontext")).Replace(" ",
"")), adminsection2).RefreshSection()
Next
End Sub
>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim sections As DataTable = Me.GetSections()
For Each section As DataRow In sections.Rows
Me.AddAdminSection(CStr(section("buttontext")))
Next
Me.Refresh()
End Sub
>
Private Function GetSections() As DataTable
Dim sections As New DataTable
Dim dataadapterSelect As New OleDbDataAdapter("SELECT buttontext
FROM
subnavigation WHERE buttontext<>'More.' AND category='" &
Request.QueryString("category") & "' ORDER BY buttonorder",
System.Configuration.ConfigurationManager.AppS ettings("connectionstring"))
dataadapterSelect.Fill(sections)
Return sections
End Function
>
Private Sub AddAdminSection(ByVal section As String)
Dim admin As adminsection2 =
CType(Page.LoadControl("~/usercontrols/adminsection2.ascx"),
adminsection2)
admin.ID = "admin" & section.Replace(" ", "")
admin.Section = section
Me.form1.Controls.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.AddAdminSection(CStr(section("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...@hotmail.comhttp://www.nathansokalski.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 19 '07 #7
If it was now friday I could make the sample.
"Nathan Sokalski" <nj********@hotmail.comschreef in bericht
news:%2****************@TK2MSFTNGP02.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:CollapsiblePanelExtender/>

(obviously the controls all have their properties, and the DataList has
it's ItemTemplate and EditItemTemplate). The property that I am having
trouble maintaining is the Collapsed property of the
CollapsiblePanelExtender 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
OleDbDataAdapter's SQL to keep the code short in the posting):

Public Sub RefreshSection()
Dim sectiontable As New DataTable
Dim sectionadapter As New OleDbDataAdapter("",
ConfigurationManager.AppSettings("connectionstring "))
sectionadapter.Fill(sectiontable)
Me.datSection.DataSource = sectiontable
Me.datSection.DataBind()
End Sub

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

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

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

Cor

"Nathan Sokalski" <nj********@hotmail.comschreef in bericht
news:eT**************@TK2MSFTNGP05.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********@hotmail.com
http://www.nathansokalski.com/

"Masudur" <mu*****@gmail.comwrote in message
news:11*********************@o11g2000prd.googleg roups.com...
On Jun 16, 10:53 am, "Nathan Sokalski" <njsokal...@hotmail.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.FindControl("admin" &
CStr(section("buttontext")).Replace(" ",
"")), adminsection2).RefreshSection()
Next
End Sub
>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim sections As DataTable = Me.GetSections()
For Each section As DataRow In sections.Rows
Me.AddAdminSection(CStr(section("buttontext")))
Next
Me.Refresh()
End Sub
>
Private Function GetSections() As DataTable
Dim sections As New DataTable
Dim dataadapterSelect As New OleDbDataAdapter("SELECT buttontext
FROM
subnavigation WHERE buttontext<>'More.' AND category='" &
Request.QueryString("category") & "' ORDER BY buttonorder",
System.Configuration.ConfigurationManager.AppS ettings("connectionstring"))
dataadapterSelect.Fill(sections)
Return sections
End Function
>
Private Sub AddAdminSection(ByVal section As String)
Dim admin As adminsection2 =
CType(Page.LoadControl("~/usercontrols/adminsection2.ascx"),
adminsection2)
admin.ID = "admin" & section.Replace(" ", "")
admin.Section = section
Me.form1.Controls.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.AddAdminSection(CStr(section("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...@hotmail.comhttp://www.nathansokalski.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 19 '07 #8

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

Similar topics

0
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...
4
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...
9
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");...
7
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 --...
2
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 =...
2
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...
3
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 <...
7
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. ...
3
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.