473,748 Members | 2,157 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 SelectedIndexCh ange 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.A dd 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 2558
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.e du> wrote in message
news:e2******** *****@TK2MSFTNG P10.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 SelectedIndexCh ange 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.A dd 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******** ******@TK2MSFTN GP12.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 "ReloadCont rol" 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(Lo adControl(Contr olToLoad))
</snip>

What is "plchldrContent "? Is that your PlaceHolder?

My PlaceHolder is called "PlaceHolde r1". I tried
"PlaceHolder1.C ontrols.Add(Loa dControl("btnSu bmit"));" 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 "ReloadCont rol" 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("Relo adControl") = 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.C ontrols.Add(Loa dControl("Contr olsFolder/MyControl.ascx" ))

ViewState("btnS ubmit") = "ControlsFo lder/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("btnS ubmit")

'---Check if the control should be reloaded (if path exists it should be
reloaded).
If PathToControl > "" Then
MyPlaceHolder.C ontrols.Add(Loa dControl())
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.e du> wrote in message
news:%2******** **********@tk2m sftngp13.phx.gb l... "S. Justin Gengo" <> wrote in message
news:ur******** ******@TK2MSFTN GP12.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 "ReloadCont rol" 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(Lo adControl(Contr olToLoad))
</snip>

What is "plchldrContent "? Is that your PlaceHolder?

My PlaceHolder is called "PlaceHolde r1". I tried
"PlaceHolder1.C ontrols.Add(Loa dControl("btnSu bmit"));" and it crashed with
"User control source files must have a .ascx file extension.".

Thanks,
blue

Nov 17 '05 #4
"S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message
news:eq******** ******@TK2MSFTN GP12.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
5376
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 controls has a button that performs a postback. My question is when the button is clicked and a postback is performed, the controls that were in the placeholder no longer appears on the screen! Am I doing something wrong here? Why are the controls back on the screen eventhough they have enable view...
9
2452
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); }
1
5695
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 DropDownList and posts the page. Now I try to get the value of what the user selected but the PlaceHolder's Controls collection is empty. I've tried turning viewstate of the PlaceHolder on and off but it doesn't make a difference (and I think I should be able to leave it off). What could be...
0
1009
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 the placeholder from my codebehind for the page On the calling page I have: Protected WithEvents PH As System.Web.UI.WebControls.PlaceHolder Protected WithEvents phMain As System.Web.UI.WebControls.PlaceHolder
3
1812
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 placeHolder, B2 will do the same with Pl2.ascx and B3 with Pl3.ascx. Each .ascx file has controls that can fire som events(button, dropList...). When I start the page, B1 is default and every control on Pl1.ascx work very fine. When I choose B2 or B3 the .ascx file is loaded in the placeholder but no...
2
3491
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 - all is well with the world. But on post back the control disappears from the placeholder. Am I missing something here Please help
0
1550
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: public delegate void SelectHandler(object sender, SelectEventArgs e); public event SelectHandler OnSelect; protected void Page_Load(object sender, EventArgs e)
2
1443
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 hide the previous one. Why does the events of the controls that are inside the second UserControl doesn't work the first time I try to rise them?
1
2034
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 i have in the files: In aspx: <table>
0
8822
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9528
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9357
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8235
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6072
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4591
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3298
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
2
2774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.