472,337 Members | 1,311 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Placeholder and Events

I have a drop-down list, a radio button list and a submit button. I'm
adding these controls to a table and I'm adding the table to a Placeholder.
I'm adding it to the Placeholder because I don't know exactly where the
table will be located on the page until runtime. Before the form control
table is added to the Placeholder, I'm adding a whole bunch of tables to the
Placeholder. This is a flowchart program and I have multiple action boxes
and decision boxes on the page.

When I add the form controls to the Placeholder, the events for the
drop-down list and radio button list stop working. It's as if they
dissapear into a black hole and after the SelectedIndexChange event is fired
for the controls, the program looks for the event but can't find it so it
skips over it. Interestingly, the submit button's event still works.

Is there a way to get my drop-down list and radio button list events to
start working again?

Is there a way to do this without using a Placeholder? I could do
this.Controls.Add but I think it would be added outside of the </HTML> tag
and the form controls have to be within the <HTML> part.
Nov 17 '05 #1
4 2471
blue,

This might be a problem with the dynamically created objects not being
recreated on post back. For an object's events to fire it must exist. That
means that if you create an object dynamically it must be recreated on post
back in order for it's events to fire.

My own web site, www.aboutfortunate.com, uses this technique and I had to
create some subroutines to place controls to load into viewstate and then
retrieve and recreate those same controls on post back.

I've placed the code I created in the code library on the site. It might
help you out to take a look at it. Just click the code library link and use
the search box to search for: "Dynamic Controls" the title of the entry you
want is: "Reload dynamically created user controls in order to use their
viewstate".

(Using viewstate of a dynamically created control has the same difficulty as
getting the control's event to fire.)

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"blue" <bl**@arizona.edu> wrote in message
news:e2*************@TK2MSFTNGP10.phx.gbl...
I have a drop-down list, a radio button list and a submit button. I'm
adding these controls to a table and I'm adding the table to a Placeholder. I'm adding it to the Placeholder because I don't know exactly where the
table will be located on the page until runtime. Before the form control
table is added to the Placeholder, I'm adding a whole bunch of tables to the Placeholder. This is a flowchart program and I have multiple action boxes
and decision boxes on the page.

When I add the form controls to the Placeholder, the events for the
drop-down list and radio button list stop working. It's as if they
dissapear into a black hole and after the SelectedIndexChange event is fired for the controls, the program looks for the event but can't find it so it
skips over it. Interestingly, the submit button's event still works.

Is there a way to get my drop-down list and radio button list events to
start working again?

Is there a way to do this without using a Placeholder? I could do
this.Controls.Add but I think it would be added outside of the </HTML> tag
and the form controls have to be within the <HTML> part.

Nov 17 '05 #2
"S. Justin Gengo" <> wrote in message
news:ur**************@TK2MSFTNGP12.phx.gbl...
blue,

This might be a problem with the dynamically created objects not being
recreated on post back. For an object's events to fire it must exist. That
means that if you create an object dynamically it must be recreated on post back in order for it's events to fire.

My own web site, www.aboutfortunate.com, uses this technique and I had to
create some subroutines to place controls to load into viewstate and then
retrieve and recreate those same controls on post back.


Justin,

Thanks for the help. I'm a little confused about your coding example. This
is partly because I'm not familiar with VB.NET.

<snip>
If CType(ViewState("ReloadControl"), String)> "" Then
</snip>

Is the "ReloadControl" part supposed to be the control that I'm testing to
see if it exists? So, if my submit button was called btnSubmit, I would put
"btnSubmit" there instead? Do I have to use the CType part? I think that's
a VB thing. I am just creating an object equal to ViewState["btnSubmit"] (I
think it has to have square brackets for C#) and if it's null I try to add
it back. The problem is, it always returns null, even on the first
page_load.

<snip>
plchldrContent.Controls.Add(LoadControl(ControlToL oad))
</snip>

What is "plchldrContent"? Is that your PlaceHolder?

My PlaceHolder is called "PlaceHolder1". I tried
"PlaceHolder1.Controls.Add(LoadControl("btnSubmit" ));" and it crashed with
"User control source files must have a .ascx file extension.".

Thanks,
blue

Nov 17 '05 #3
blue,

In my example I'm reloading a single control.

Now my responses to your questions (in-line):
<snip>
If CType(ViewState("ReloadControl"), String)> "" Then
</snip>

Is the "ReloadControl" part supposed to be the control that I'm testing to
see if it exists? So, if my submit button was called btnSubmit, I would put "btnSubmit" there instead?
No, you would not put btnSubmit in there. When I load the control for the
first time, I store the path to the control I just loaded in view state:

'---controlToLoad hold the path to the control (i.e.
"controls/Biography.ascx")
ViewState("ReloadControl") = controlToLoad

If that value exists in viewstate on a post back I have everything I need to
reload the control.

Do I have to use the CType part? I think that's
a VB thing.
CType() '---Cast As Type (Casts the object stored in viewstate as a string.)

I am just creating an object equal to ViewState["btnSubmit"] (I
think it has to have square brackets for C#) and if it's null I try to add
it back. The problem is, it always returns null, even on the first
page_load.
'---This would not be used on first page load at all.

'---Load your control the first time the same way you always do.

'---Just after you load your control (or just before for that matter) store
the path to the ' control you're loading in view state.

MyPlaceHolder.Controls.Add(LoadControl("ControlsFo lder/MyControl.ascx"))

ViewState("btnSubmit") = "ControlsFolder/MyControl.ascx"
'---Next in the page load subroutine add in code that fires on post back
only.
' Then check if there is viewstate for your control. If there is reload
it.
' In VB.Net it would look like:

If Not IsPostBack Then
'---Get path from viewstate.
Dim PathToControl As String = ViewState("btnSubmit")

'---Check if the control should be reloaded (if path exists it should be
reloaded).
If PathToControl > "" Then
MyPlaceHolder.Controls.Add(LoadControl())
End If
End If
Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"blue" <bl**@arizona.edu> wrote in message
news:%2******************@tk2msftngp13.phx.gbl... "S. Justin Gengo" <> wrote in message
news:ur**************@TK2MSFTNGP12.phx.gbl...
blue,

This might be a problem with the dynamically created objects not being
recreated on post back. For an object's events to fire it must exist. That means that if you create an object dynamically it must be recreated on post
back in order for it's events to fire.

My own web site, www.aboutfortunate.com, uses this technique and I had to create some subroutines to place controls to load into viewstate and then retrieve and recreate those same controls on post back.


Justin,

Thanks for the help. I'm a little confused about your coding example.

This is partly because I'm not familiar with VB.NET.

<snip>
If CType(ViewState("ReloadControl"), String)> "" Then
</snip>

Is the "ReloadControl" part supposed to be the control that I'm testing to
see if it exists? So, if my submit button was called btnSubmit, I would put "btnSubmit" there instead? Do I have to use the CType part? I think that's a VB thing. I am just creating an object equal to ViewState["btnSubmit"] (I think it has to have square brackets for C#) and if it's null I try to add
it back. The problem is, it always returns null, even on the first
page_load.

<snip>
plchldrContent.Controls.Add(LoadControl(ControlToL oad))
</snip>

What is "plchldrContent"? Is that your PlaceHolder?

My PlaceHolder is called "PlaceHolder1". I tried
"PlaceHolder1.Controls.Add(LoadControl("btnSubmit" ));" and it crashed with
"User control source files must have a .ascx file extension.".

Thanks,
blue

Nov 17 '05 #4
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:eq**************@TK2MSFTNGP12.phx.gbl...
blue,

In my example I'm reloading a single control.

Now my responses to your questions (in-line):


Justin,

I found a C# example that I used to fix the problem:
http://msdn.microsoft.com/library/de...imevisualc.asp

I couldn't have done it without your help.

Thanks,

Cindy
Nov 17 '05 #5

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

Similar topics

1
by: Angel | last post by:
I have added controls to the placeholder control. All the controls that were added have EnableViewState = true including the placeholder. One of the...
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...
1
by: Simon Wallis | last post by:
Hi, I have a PlaceHolder on a place, to which I add a DropDownList (using myPlaceHolder.Controls.Add(ddl). The user selects something from the...
0
by: Chris Kettenbach | last post by:
How do I get the page to respond to events on a dynamically loaded user control in a placholder control? I am trying to reference the control in...
3
by: PKin via DotNetMonster.com | last post by:
Hi, I have a web page with a radioButtonList with 3 buttons (B1,B2 and B3) and a placeholder. B1 will put an .ascx file (Pl1.ascx) in the...
2
by: Vishal Gupta | last post by:
Hi all, I have a placeholder control on an ASPX page. I dynamically add a few button control and label control to the placeholder from code -...
0
by: seigo | last post by:
Hello, I faced with the following problem. I have a PlaceHolder on a page and a few UserControls which have custom events, for instance: ...
2
by: David | last post by:
I have a UserControl loaded into a PlaceHolder and I have a button there which is suppose to load another UserControl into the same PlaceHolder and...
1
by: AdamK. | last post by:
/* Hello, Its maybe simple but i cant fix it :( First i would say sry for my english, but i will try my best :) Its web application and what...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

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.