keyongtech


  keyongtech > dotnet.framework.aspnet.* > dotnet.framework.aspnet.main > 01/2005

 #1  
01-06-05, 08:52 PM
Stu
Hi,

I am creating a control in a PlaceHolder like so:

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDelete.Click
Dim ctrl As AcceptOrCancel =
CType(Page.LoadControl("controls/AcceptOrCancel.ascx"), AcceptOrCancel)
PlaceHolder1.Controls.Add(ctrl)

Session("CurrentControl") = "AcceptOrCancel.ascx"
End Sub

When I post the page back the dynamically created control just disappears.
Is there any way of persisting a control across page loads?

This is part of an online image editor in a cms. Different controls will be
loaded in to the placeholder depending on which buton is pressed
(delete,resize,crop etc) - is there any way of detecting a control loaded in
to the placeholder and recreating it automatically? I've been trying call
this from the Page_Init event but the session isn't loaded until further in
to the page execution order:

Private Sub LoadDynamicControls()

If Session("CurrentControl") = "AcceptOrCancel.ascx" Then
Dim ctrl As AcceptOrCancel =
CType(Page.LoadControl("controls/AcceptOrCancel.ascx"), AcceptOrCancel)
PlaceHolder1.Controls.Add(ctrl)

elseif Session("CurrentControl") = "ResizeImage.ascx" Then
Dim ctrl As ResizeImage=
CType(Page.LoadControl("controls/ResizeImage.ascx"), ResizeImage)
PlaceHolder1.Controls.Add(ctrl)

End If

End Sub

Is there any way of programatically adding the control to the page viewstate
so it persists once it is created once?

Sorry for the long question but I've been stuck for hours.

Thanks in advance,

Stu
 #2  
01-06-05, 08:56 PM
Marina
No, in the sense that you have to go through the code that will recreate the
control. Normally, with things hard coded onto the page, the asp.net runtime
does all this for you. When it's dynamic, you need to instantiate it, and
add it.

But yes, in the sense that if you have viewstate enabled, you control's
state shoudl be restored. So if it had a textbox, whatever the user typed
into the textbox should appear.

"Stu" <s.lock> wrote in message
news:4028
[..]
 #3  
01-06-05, 09:38 PM
Karl Seguin
You can check out Denis Bauer's DynamicPlaceholder which exists for just
this type of problem

http://www.denisbauer.com/ASPNETCont...aceholder.aspx

Karl
 #4  
01-06-05, 09:57 PM
Stu
Many thanks - that looks ideal (and quick!)



"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:3820
[..]
Similar Threads
Dynamic controls, postbacks, and view state

My application calls for a lookup table in which the user can add records. When the application is run, an html table will be created dynamically to show checkboxes (and...

Dynamic Controls, Postbacks, ViewState, Oh My!

Hello, I am loading several user controls dynamically in OnInit() like this: ucListBoxSelections ucLocation...

Persisting dynamic controls

Hi, In my ASP.NET application, I want to be able to dynamically create RadioButtonLists and/or CheckBoxLists according to what is in my database. I wrote routines to create...

Dynamic runtime controls, postbacks, Page_Init, Viewstate et al

Hi, I've searched the newsgroup and other sources to understand how to handle runtime controls and see I'm not the only one who's confused, but I'm still not quite sure of...

Persisting dynamic controls

Hi all, My web form creates & displays dynamic controls when a user clicks a button (code below). No problem. But how do I persist a new control? Every postback destroys the...


All times are GMT. The time now is 04:57 AM. | Privacy Policy