473,699 Members | 3,022 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

creating dynamic controls out of static controls

hi all,

I have this seemingly simple problem. I have lost a lot of time on it
though.

When a user selects a value from a dropdownlist (static control) a
dynamic control is generated. I have to create the dynamic controls
in the OnInit stage of the lifecycle. Since data from static controls
is not yet available in the OnInit stage I can't know what dynamic
control I have to create.

How can I overcome this problem? Since this question has probably
already been answered a good tutorial will also do of course. I have
been looking on the net but no success.

Thanks in advance
Stijn

Feb 12 '07 #1
9 3625
When you create controls first time, do it in Page_Load event or later. When
you need to re-create them on postbacks, do it in PreInit event.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Tarscher" <ta******@gmail .comwrote in message
news:11******** **************@ l53g2000cwa.goo glegroups.com.. .
hi all,

I have this seemingly simple problem. I have lost a lot of time on it
though.

When a user selects a value from a dropdownlist (static control) a
dynamic control is generated. I have to create the dynamic controls
in the OnInit stage of the lifecycle. Since data from static controls
is not yet available in the OnInit stage I can't know what dynamic
control I have to create.

How can I overcome this problem? Since this question has probably
already been answered a good tutorial will also do of course. I have
been looking on the net but no success.

Thanks in advance
Stijn

Feb 12 '07 #2
Thanks Eliyah for the quick answer. Some moet questions tough.

You say I have to recreate the controls on the PreInit even. But how
can I know the state of the drop down list (a static control) in the
PreInit stage? I can thus not create my dynamic controls since I don't
know what's in the drop down list.

Can you please explain me what I do when the dropdownlist
SelectedIndexCh anged had fired?

Thanks
Stijn

On 12 feb, 15:34, "Eliyahu Goldin"
<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
When you create controls first time, do it in Page_Load event or later. When
you need to re-create them on postbacks, do it in PreInit event.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

"Tarscher" <tarsc...@gmail .comwrote in message

news:11******** **************@ l53g2000cwa.goo glegroups.com.. .
hi all,
I have this seemingly simple problem. I have lost a lot of time on it
though.
When a user selects a value from a dropdownlist (static control) a
dynamic control is generated. I have to create the dynamic controls
in the OnInit stage of the lifecycle. Since data from static controls
is not yet available in the OnInit stage I can't know what dynamic
control I have to create.
How can I overcome this problem? Since this question has probably
already been answered a good tutorial will also do of course. I have
been looking on the net but no success.
Thanks in advance
Stijn

Feb 12 '07 #3
Stijn,

You need to re-create dynamic controls only if you are in a postback and the
controls need to pickup their properties that arrive to the server in the
same postback. In your case, you seem to create controls every postback from
scratch depending on the selected ddl item. If it is the case, I don't see
why can't you wait with creating controls till the stage where you already
know what to create.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Tarscher" <ta******@gmail .comwrote in message
news:11******** *************@p 10g2000cwp.goog legroups.com...
Thanks Eliyah for the quick answer. Some moet questions tough.

You say I have to recreate the controls on the PreInit even. But how
can I know the state of the drop down list (a static control) in the
PreInit stage? I can thus not create my dynamic controls since I don't
know what's in the drop down list.

Can you please explain me what I do when the dropdownlist
SelectedIndexCh anged had fired?

Thanks
Stijn

On 12 feb, 15:34, "Eliyahu Goldin"
<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
>When you create controls first time, do it in Page_Load event or later.
When
you need to re-create them on postbacks, do it in PreInit event.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

"Tarscher" <tarsc...@gmail .comwrote in message

news:11******* *************** @l53g2000cwa.go oglegroups.com. ..
hi all,
I have this seemingly simple problem. I have lost a lot of time on it
though.
When a user selects a value from a dropdownlist (static control) a
dynamic control is generated. I have to create the dynamic controls
in the OnInit stage of the lifecycle. Since data from static controls
is not yet available in the OnInit stage I can't know what dynamic
control I have to create.
How can I overcome this problem? Since this question has probably
already been answered a good tutorial will also do of course. I have
been looking on the net but no success.
Thanks in advance
Stijn


Feb 12 '07 #4
Eliyahu, what i try:

- On the SelectedIndexCh anged event of the dropdownlist I read out the
DDL data and create the appropriate controls
protected void KeywordDropDown List_SelectedIn dexChanged(obje ct
sender, EventArgs e)
{
string selectedKeyword =
KeywordDropDown List.SelectedVa lue.ToString();
DrawKeywordEdit or(selectedKeyw ord);
}
- I then try to recreate the control in the Preinit stage but this
seems to fail.
base.OnPreInit( e);
IKeywordEditor myIKE = EditorHolder.Fi ndControl("Keyw ordEditor") as
IKeywordEditor;
The EditorHolder is not known in this page (it is in the init stage).
When I recreate it in the Init stage I always get a null returned. The
KeywordEditor control is thus not found.

I'm probably missing something crucial here.

Stijn
On 12 feb, 16:51, "Eliyahu Goldin"
<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
Stijn,

You need to re-create dynamic controls only if you are in a postback and the
controls need to pickup their properties that arrive to the server in the
same postback. In your case, you seem to create controls every postback from
scratch depending on the selected ddl item. If it is the case, I don't see
why can't you wait with creating controls till the stage where you already
know what to create.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

"Tarscher" <tarsc...@gmail .comwrote in message

news:11******** *************@p 10g2000cwp.goog legroups.com...
Thanks Eliyah for the quick answer. Some moet questions tough.
You say I have to recreate the controls on the PreInit even. But how
can I know the state of the drop down list (a static control) in the
PreInit stage? I can thus not create my dynamic controls since I don't
know what's in the drop down list.
Can you please explain me what I do when the dropdownlist
SelectedIndexCh anged had fired?
Thanks
Stijn
On 12 feb, 15:34, "Eliyahu Goldin"
<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
When you create controls first time, do it in Page_Load event or later.
When
you need to re-create them on postbacks, do it in PreInit event.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
"Tarscher" <tarsc...@gmail .comwrote in message
>news:11******* *************** @l53g2000cwa.go oglegroups.com. ..
hi all,
I have this seemingly simple problem. I have lost a lot of time on it
though.
When a user selects a value from a dropdownlist (static control) a
dynamic control is generated. I have to create the dynamic controls
in the OnInit stage of the lifecycle. Since data from static controls
is not yet available in the OnInit stage I can't know what dynamic
control I have to create.
How can I overcome this problem? Since this question has probably
already been answered a good tutorial will also do of course. I have
been looking on the net but no success.
Thanks in advance
Stijn

Feb 12 '07 #5
I just read this interchange, and I fear that you have created a flawed
design. It's a case of "the cart before the horse" here. Better revisit your
logic and see if you cannot find a less - complicated way to reach your goal.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Tarscher" wrote:
Eliyahu, what i try:

- On the SelectedIndexCh anged event of the dropdownlist I read out the
DDL data and create the appropriate controls
protected void KeywordDropDown List_SelectedIn dexChanged(obje ct
sender, EventArgs e)
{
string selectedKeyword =
KeywordDropDown List.SelectedVa lue.ToString();
DrawKeywordEdit or(selectedKeyw ord);
}
- I then try to recreate the control in the Preinit stage but this
seems to fail.
base.OnPreInit( e);
IKeywordEditor myIKE = EditorHolder.Fi ndControl("Keyw ordEditor") as
IKeywordEditor;
The EditorHolder is not known in this page (it is in the init stage).
When I recreate it in the Init stage I always get a null returned. The
KeywordEditor control is thus not found.

I'm probably missing something crucial here.

Stijn
On 12 feb, 16:51, "Eliyahu Goldin"
<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
Stijn,

You need to re-create dynamic controls only if you are in a postback and the
controls need to pickup their properties that arrive to the server in the
same postback. In your case, you seem to create controls every postback from
scratch depending on the selected ddl item. If it is the case, I don't see
why can't you wait with creating controls till the stage where you already
know what to create.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

"Tarscher" <tarsc...@gmail .comwrote in message

news:11******** *************@p 10g2000cwp.goog legroups.com...
Thanks Eliyah for the quick answer. Some moet questions tough.
You say I have to recreate the controls on the PreInit even. But how
can I know the state of the drop down list (a static control) in the
PreInit stage? I can thus not create my dynamic controls since I don't
know what's in the drop down list.
Can you please explain me what I do when the dropdownlist
SelectedIndexCh anged had fired?
Thanks
Stijn
On 12 feb, 15:34, "Eliyahu Goldin"
<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
>When you create controls first time, do it in Page_Load event or later.
>When
>you need to re-create them on postbacks, do it in PreInit event.
>--
>Eliyahu Goldin,
>Software Developer & Consultant
>Microsoft MVP
>[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
>"Tarscher" <tarsc...@gmail .comwrote in message
>>news:11****** *************** *@l53g2000cwa.g ooglegroups.com ...
hi all,
I have this seemingly simple problem. I have lost a lot of time on it
though.
When a user selects a value from a dropdownlist (static control) a
dynamic control is generated. I have to create the dynamic controls
in the OnInit stage of the lifecycle. Since data from static controls
is not yet available in the OnInit stage I can't know what dynamic
control I have to create.
How can I overcome this problem? Since this question has probably
already been answered a good tutorial will also do of course. I have
been looking on the net but no success.
Thanks in advance
Stijn


Feb 12 '07 #6
I assume that what I want to do has been done 1000 of times but maybe
I implement it in the wrong way?

What I want to do:
A dropdownlist is populated with editornames. An editor is a user
control. When the user makes a choice out of the DDL, the user control
(editor) is rendered to the screen. I make the user control a dynamic
control that I add to a placeholder. The fact that the user control
needs to be dynamic is actually the only restrain. I really don't see
how I can pass data to the dynamic control (editors).

Someone has an idea on how to tackle this problem?

Thanks
Stijn
On 12 feb, 18:05, Peter Bromberg [C# MVP]
<pbromb...@yaho o.yabbadabbadoo .comwrote:
I just read this interchange, and I fear that you have created a flawed
design. It's a case of "the cart before the horse" here. Better revisit your
logic and see if you cannot find a less - complicated way to reach your goal.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net

"Tarscher" wrote:
Eliyahu, what i try:
- On the SelectedIndexCh anged event of the dropdownlist I read out the
DDL data and create the appropriate controls
protected void KeywordDropDown List_SelectedIn dexChanged(obje ct
sender, EventArgs e)
{
string selectedKeyword =
KeywordDropDown List.SelectedVa lue.ToString();
DrawKeywordEdit or(selectedKeyw ord);
}
- I then try to recreate the control in the Preinit stage but this
seems to fail.
base.OnPreInit( e);
IKeywordEditor myIKE = EditorHolder.Fi ndControl("Keyw ordEditor") as
IKeywordEditor;
The EditorHolder is not known in this page (it is in the init stage).
When I recreate it in the Init stage I always get a null returned. The
KeywordEditor control is thus not found.
I'm probably missing something crucial here.
Stijn
On 12 feb, 16:51, "Eliyahu Goldin"
<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
Stijn,
You need to re-create dynamic controls only if you are in a postback and the
controls need to pickup their properties that arrive to the server in the
same postback. In your case, you seem to create controls every postback from
scratch depending on the selected ddl item. If it is the case, I don't see
why can't you wait with creating controls till the stage where you already
know what to create.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
"Tarscher" <tarsc...@gmail .comwrote in message
>news:11******* **************@ p10g2000cwp.goo glegroups.com.. .
Thanks Eliyah for the quick answer. Some moet questions tough.
You say I have to recreate the controls on the PreInit even. But how
can I know the state of the drop down list (a static control) in the
PreInit stage? I can thus not create my dynamic controls since I don't
know what's in the drop down list.
Can you please explain me what I do when the dropdownlist
SelectedIndexCh anged had fired?
Thanks
Stijn
On 12 feb, 15:34, "Eliyahu Goldin"
<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
When you create controls first time, do it in Page_Load event or later.
When
you need to re-create them on postbacks, do it in PreInit event.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
"Tarscher" <tarsc...@gmail .comwrote in message
>news:11******* *************** @l53g2000cwa.go oglegroups.com. ..
hi all,
I have this seemingly simple problem. I have lost a lot of time on it
though.
When a user selects a value from a dropdownlist (static control) a
dynamic control is generated. I have to create the dynamic controls
in the OnInit stage of the lifecycle. Since data from static controls
is not yet available in the OnInit stage I can't know what dynamic
control I have to create.
How can I overcome this problem? Since this question has probably
already been answered a good tutorial will also do of course. I have
been looking on the net but no success.
Thanks in advance
Stijn

Feb 13 '07 #7
Stijn,

I personally hardly ever create any controls dynamically. Usually you can
achieve the same with hidden static controls. Make only one of them visible
at the time. If hide controls by setting Visible=false, they won't get
rendered to the client which is exactly the same effect as not creating them
in the first place.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Tarscher" <ta******@gmail .comwrote in message
news:11******** *************@a 75g2000cwd.goog legroups.com...
>I assume that what I want to do has been done 1000 of times but maybe
I implement it in the wrong way?

What I want to do:
A dropdownlist is populated with editornames. An editor is a user
control. When the user makes a choice out of the DDL, the user control
(editor) is rendered to the screen. I make the user control a dynamic
control that I add to a placeholder. The fact that the user control
needs to be dynamic is actually the only restrain. I really don't see
how I can pass data to the dynamic control (editors).

Someone has an idea on how to tackle this problem?

Thanks
Stijn
On 12 feb, 18:05, Peter Bromberg [C# MVP]
<pbromb...@yaho o.yabbadabbadoo .comwrote:
>I just read this interchange, and I fear that you have created a flawed
design. It's a case of "the cart before the horse" here. Better revisit
your
logic and see if you cannot find a less - complicated way to reach your
goal.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net

"Tarscher" wrote:
Eliyahu, what i try:
- On the SelectedIndexCh anged event of the dropdownlist I read out the
DDL data and create the appropriate controls
protected void KeywordDropDown List_SelectedIn dexChanged(obje ct
sender, EventArgs e)
{
string selectedKeyword =
KeywordDropDown List.SelectedVa lue.ToString();
DrawKeywordEdit or(selectedKeyw ord);
}
- I then try to recreate the control in the Preinit stage but this
seems to fail.
base.OnPreInit( e);
IKeywordEditor myIKE =
EditorHolder.Fi ndControl("Keyw ordEditor") as
IKeywordEditor;
The EditorHolder is not known in this page (it is in the init stage).
When I recreate it in the Init stage I always get a null returned. The
KeywordEditor control is thus not found.
I'm probably missing something crucial here.
Stijn
On 12 feb, 16:51, "Eliyahu Goldin"
<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
Stijn,
You need to re-create dynamic controls only if you are in a postback
and the
controls need to pickup their properties that arrive to the server in
the
same postback. In your case, you seem to create controls every
postback from
scratch depending on the selected ddl item. If it is the case, I
don't see
why can't you wait with creating controls till the stage where you
already
know what to create.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
"Tarscher" <tarsc...@gmail .comwrote in message
>news:11******* **************@ p10g2000cwp.goo glegroups.com.. .
Thanks Eliyah for the quick answer. Some moet questions tough.
You say I have to recreate the controls on the PreInit even. But
how
can I know the state of the drop down list (a static control) in
the
PreInit stage? I can thus not create my dynamic controls since I
don't
know what's in the drop down list.
Can you please explain me what I do when the dropdownlist
SelectedIndexCh anged had fired?
Thanks
Stijn
On 12 feb, 15:34, "Eliyahu Goldin"
<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
When you create controls first time, do it in Page_Load event or
later.
When
you need to re-create them on postbacks, do it in PreInit event.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
"Tarscher" <tarsc...@gmail .comwrote in message
>news:11******* *************** @l53g2000cwa.go oglegroups.com. ..
hi all,
I have this seemingly simple problem. I have lost a lot of time
on it
though.
When a user selects a value from a dropdownlist (static control)
a
dynamic control is generated. I have to create the dynamic
controls
in the OnInit stage of the lifecycle. Since data from static
controls
is not yet available in the OnInit stage I can't know what
dynamic
control I have to create.
How can I overcome this problem? Since this question has
probably
already been answered a good tutorial will also do of course. I
have
been looking on the net but no success.
Thanks in advance
Stijn


Feb 13 '07 #8
Eliyaha, that's the technique I currently use but this makes it hard
to add more user controls. And that's something I really want to
avoid.

On 13 feb, 10:33, "Eliyahu Goldin"
<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
Stijn,

I personally hardly ever create any controls dynamically. Usually you can
achieve the same with hidden static controls. Make only one of them visible
at the time. If hide controls by setting Visible=false, they won't get
rendered to the client which is exactly the same effect as not creating them
in the first place.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

"Tarscher" <tarsc...@gmail .comwrote in message

news:11******** *************@a 75g2000cwd.goog legroups.com...
I assume that what I want to do has been done 1000 of times but maybe
I implement it in the wrong way?
What I want to do:
A dropdownlist is populated with editornames. An editor is a user
control. When the user makes a choice out of the DDL, the user control
(editor) is rendered to the screen. I make the user control a dynamic
control that I add to a placeholder. The fact that the user control
needs to be dynamic is actually the only restrain. I really don't see
how I can pass data to the dynamic control (editors).
Someone has an idea on how to tackle this problem?
Thanks
Stijn
On 12 feb, 18:05, Peter Bromberg [C# MVP]
<pbromb...@yaho o.yabbadabbadoo .comwrote:
I just read this interchange, and I fear that you have created a flawed
design. It's a case of "the cart before the horse" here. Better revisit
your
logic and see if you cannot find a less - complicated way to reach your
goal.
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Tarscher" wrote:
Eliyahu, what i try:
- On the SelectedIndexCh anged event of the dropdownlist I read out the
DDL data and create the appropriate controls
protected void KeywordDropDown List_SelectedIn dexChanged(obje ct
sender, EventArgs e)
{
string selectedKeyword =
KeywordDropDown List.SelectedVa lue.ToString();
DrawKeywordEdit or(selectedKeyw ord);
}
- I then try to recreate the control in the Preinit stage but this
seems to fail.
base.OnPreInit( e);
IKeywordEditor myIKE =
EditorHolder.Fi ndControl("Keyw ordEditor") as
IKeywordEditor;
The EditorHolder is not known in this page (it is in the init stage).
When I recreate it in the Init stage I always get a null returned. The
KeywordEditor control is thus not found.
I'm probably missing something crucial here.
Stijn
On 12 feb, 16:51, "Eliyahu Goldin"
<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
Stijn,
You need to re-create dynamic controls only if you are in a postback
and the
controls need to pickup their properties that arrive to the server in
the
same postback. In your case, you seem to create controls every
postback from
scratch depending on the selected ddl item. If it is the case, I
don't see
why can't you wait with creating controls till the stage where you
already
know what to create.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
"Tarscher" <tarsc...@gmail .comwrote in message
>news:11******* **************@ p10g2000cwp.goo glegroups.com.. .
Thanks Eliyah for the quick answer. Some moet questions tough.
You say I have to recreate the controls on the PreInit even. But
how
can I know the state of the drop down list (a static control) in
the
PreInit stage? I can thus not create my dynamic controls since I
don't
know what's in the drop down list.
Can you please explain me what I do when the dropdownlist
SelectedIndexCh anged had fired?
Thanks
Stijn
On 12 feb, 15:34, "Eliyahu Goldin"
<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
When you create controls first time, do it in Page_Load event or
later.
When
you need to re-create them on postbacks, do it in PreInit event.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
"Tarscher" <tarsc...@gmail .comwrote in message
>news:11******* *************** @l53g2000cwa.go oglegroups.com. ..
hi all,
I have this seemingly simple problem. I have lost a lot of time
on it
though.
When a user selects a value from a dropdownlist (static control)
a
dynamic control is generated. I have to create the dynamic
controls
in the OnInit stage of the lifecycle. Since data from static
controls
is not yet available in the OnInit stage I can't know what
dynamic
control I have to create.
How can I overcome this problem? Since this question has
probably
already been answered a good tutorial will also do of course. I
have
been looking on the net but no success.
Thanks in advance
Stijn

Feb 13 '07 #9
You could take the hidden controls a bit further... place them all in
divs and set the style "display" property to "none". Absolute-
position the divs to the same location on the page. Set "display" to
"block" for the one that corresponds to the default selection in your
dropdown (if there is one.) Add a hidden form field whose value is
set to the ID of the initially selected control (or "" if there isn't
one.) Make dropdown option values the same as the corresponding div
ids and then add a client onchange handler
(onchange="Togg leEditor(this); ") which could call a function something
like the following

function ToggleEditor(se lect) {
if (select.selecte dIndex >= 0) {
var hidden = document.getEle mentById('hidde nSelectedDivID' );
if (hidden) {
var elem = document.getEle mentById(hidden .value);
if (elem) {elem.style.dis play = 'none';}
hidden.value = '';
elem =
document.getEle mentById(select .options(select .selectedIndex) .value);
if (elem) {
elem.style.disp lay = 'block';
hidden.value = elem.id;
}
}
}
}

This way you can change editors without a postback, unless there is
other stuff you do with them on postbacks like populate them with data
that can't be predetermined.

On Feb 13, 5:01 am, "Tarscher" <tarsc...@gmail .comwrote:
Eliyaha, that's the technique I currently use but this makes it hard
to add more user controls. And that's something I really want to
avoid.

On 13 feb, 10:33, "Eliyahu Goldin"

<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
Stijn,
I personally hardly ever create any controls dynamically. Usually you can
achieve the same with hidden static controls. Make only one of them visible
at the time. If hide controls by setting Visible=false, they won't get
rendered to the client which is exactly the same effect as not creating them
in the first place.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
"Tarscher" <tarsc...@gmail .comwrote in message
news:11******** *************@a 75g2000cwd.goog legroups.com...
>I assume that what I want to do has been done 1000 of times but maybe
I implement it in the wrong way?
What I want to do:
A dropdownlist is populated with editornames. An editor is a user
control. When the user makes a choice out of the DDL, the user control
(editor) is rendered to the screen. I make the user control a dynamic
control that I add to a placeholder. The fact that the user control
needs to be dynamic is actually the only restrain. I really don't see
how I can pass data to the dynamic control (editors).
Someone has an idea on how to tackle this problem?
Thanks
Stijn
On 12 feb, 18:05, Peter Bromberg [C# MVP]
<pbromb...@yaho o.yabbadabbadoo .comwrote:
>I just read this interchange, and I fear that you have created a flawed
>design. It's a case of "the cart before the horse" here. Better revisit
>your
>logic and see if you cannot find a less - complicated way to reach your
>goal.
>Peter
>--
>Site: http://www.eggheadcafe.com
>UnBlog: http://petesbloggerama.blogspot.com
>Short urls & more: http://ittyurl.net
>"Tarscher" wrote:
Eliyahu, what i try:
- On the SelectedIndexCh anged event of the dropdownlist I read out the
DDL data and create the appropriate controls
protected void KeywordDropDown List_SelectedIn dexChanged(obje ct
sender, EventArgs e)
{
string selectedKeyword =
KeywordDropDown List.SelectedVa lue.ToString();
DrawKeywordEdit or(selectedKeyw ord);
}
- I then try to recreate the control in the Preinit stage but this
seems to fail.
base.OnPreInit( e);
IKeywordEditor myIKE =
EditorHolder.Fi ndControl("Keyw ordEditor") as
IKeywordEditor;
The EditorHolder is not known in this page (it is in the init stage).
When I recreate it in the Init stage I always get a null returned. The
KeywordEditor control is thus not found.
I'm probably missing something crucial here.
Stijn
On 12 feb, 16:51, "Eliyahu Goldin"
<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
Stijn,
You need to re-create dynamic controls only if you are in a postback
and the
controls need to pickup their properties that arrive to the server in
the
same postback. In your case, you seem to create controls every
postback from
scratch depending on the selected ddl item. If it is the case, I
don't see
why can't you wait with creating controls till the stage where you
already
know what to create.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
"Tarscher" <tarsc...@gmail .comwrote in message
>news:11******* **************@ p10g2000cwp.goo glegroups.com.. .
Thanks Eliyah for the quick answer. Some moet questions tough.
You say I have to recreate the controls on the PreInit even. But
how
can I know the state of the drop down list (a static control) in
the
PreInit stage? I can thus not create my dynamic controls since I
don't
know what's in the drop down list.
Can you please explain me what I do when the dropdownlist
SelectedIndexCh anged had fired?
Thanks
Stijn
On 12 feb, 15:34, "Eliyahu Goldin"
<REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
When you create controls first time, do it in Page_Load event or
later.
When
you need to re-create them on postbacks, do it in PreInit event.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
"Tarscher" <tarsc...@gmail .comwrote in message
>news:11******* *************** @l53g2000cwa.go oglegroups.com. ..
hi all,
I have this seemingly simple problem. I have lost a lot of time
on it
though.
When a user selects a value from a dropdownlist (static control)
a
dynamic control is generated. I have to create the dynamic
controls
in the OnInit stage of the lifecycle. Since data from static
controls
is not yet available in the OnInit stage I can't know what
dynamic
control I have to create.
How can I overcome this problem? Since this question has
probably
already been answered a good tutorial will also do of course. I
have
been looking on the net but no success.
Thanks in advance
Stijn- Hide quoted text -

- Show quoted text -

Feb 13 '07 #10

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

Similar topics

6
2915
by: MikeY | last post by:
Hi Everyone, Does anyone know where I can get my hands on a sample with source code of a simple dynamic button control in C# Windows form. I am looking for a sample that uses a class library that sets the properties send/passed from the main windows form. I'm having problems with the class library, the button control collection and my referencing it ie this.Control.Add(aControl);. Any and all help is appreciated. Thanks in advance.
1
2003
by: hybrid | last post by:
I have problems in understanding the behavior of the events triggered by dynamically created controls over a webform. Could you help me? In a webform, I have a static PlaceHolder PH containing a table of controls, dynamically generated. Among these, a linkbutton (LinkBtn) to which have attached a click handler method, LinkBtn_Click(...) . Generally it works fine, but if in the LinkBtn_Click(...) code I try to access a webform control,...
6
6013
by: Glenn Owens | last post by:
I have an ASP.Net page on which there are serveral static controls (listboxes, radiobuttonlist and textboxes). These controls are used to create criteria from which the code-behind will dynamically create 1-n datagrids. When the Submit button is clicked I need to save (in viewstate) the contents of the criteria controls so that I can recreate the dynamic DataGrid(s) in the LoadViewState (overloaded method). I need to do this so that the...
2
2551
by: Dave Williamson | last post by:
When a ASPX page is created with dynamic controls based on what the user is doing the programmer must recreate the dynamic controls again on PostBack in the Page_Load so that it's events are wired and are called like a static control. Here is the problem that I need to solve. The processing overhead that occurs to determine what dynamic controls need to be added involves business logic and a query or queries of data in a sql server...
2
4565
by: Patrick | last post by:
I want to define a set of web-form templates in XML and render the equivalent web-form with ASP.NET, then process any input server controls on the form. Reading the XML file from Page_load is easy, but 1) How do I set about dynamically creating user controls (like TextBox, TextArea) --- simply Declare and initialised (new) the user controls?? How do I "place" it graphically on the form. Ideally, I want them to lay out in a table, one...
3
1854
by: WebBuilder451 | last post by:
I have a series of dynamic link buttons created based upon a datareader. I've added a click event and it calls the sub ok: example: "while loop through the reader" Dim ltrCtrl As New LiteralControl Dim lbtnCtrl As New LinkButton ltrCtrl.Text = "<br>" lbtnCtrl.Text = "WE: " & dtrCal(10).ToString lbtnCtrl.ToolTip = dtrCal(10).ToString & " these events" & dtrCal(1) lbtnCtrl.ID = "wecc" & i.ToString
7
2217
by: Varangian | last post by:
Hello is creating controls at runtime the same as designtime ? will a page be faster if controls are created at designtime rather than at runtime ? If so why ? thanks :)
5
1998
by: Guillaume BRAUX | last post by:
Hello, What I want to do is to add a userControl to a form class witch is a different class from the one the button is generated. For example, I want to instanciate a label in "class1" and add it ("show it") on a WinForm situated in "class2" (without having to add code to class2 !) The problem is that I need to instanciate "class2" from "class1" to be able to do a class2.controls.add(myLabel) in class1..
1
1896
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating forms / html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to show - text boxes, input boxes, buttons, hyperlinks ie the usual. The data is not obtained directly from a database.
0
8704
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9187
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
9053
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...
1
8936
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8894
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7776
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
4390
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
4636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2360
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.