Dynamicly adding controls after Page_Load event

G

GS

Hi,

I dynamicly add custom control in SelectedIndexChanged even of GridView which is firing after Page_Load. My control is not being rendered to page becouse of that (I assume). How to avoid this situation? Sample below

protected void dgrCompanies_SelectedIndexChanged(object sender, EventArgs e)
{
GoogleControl MyGoogleControl = new GoogleControl ();
PlaceHolderForMap.Controls.Add(MyGoogleControl);
}
 
T

Terry Burns

No, your conrol will be rendered after PreRender which happens after this event.

Have you set your control to visible
Have you positioned your control
Have you checked the Z-Order of the control
Is the PlaceHolder visible.
Have you checked that this should appear with no data in it for example ?


--
Terry Burns
http://TrainingOn.net



Hi,

I dynamicly add custom control in SelectedIndexChanged even of GridView which is firing after Page_Load. My control is not being rendered to page becouse of that (I assume). How to avoid this situation? Sample below

protected void dgrCompanies_SelectedIndexChanged(object sender, EventArgs e)
{
GoogleControl MyGoogleControl = new GoogleControl ();
PlaceHolderForMap.Controls.Add(MyGoogleControl);
}
 
G

GS

Control is not positioned on webpage at all. My understanding that I can load it programmatically without putting it on webpage (one reference is set at <%@ reference
Placeholder is visible. Code below works fine for TextBox control for example but not for custom control.


No, your conrol will be rendered after PreRender which happens after this event.

Have you set your control to visible
Have you positioned your control
Have you checked the Z-Order of the control
Is the PlaceHolder visible.
Have you checked that this should appear with no data in it for example ?


--
Terry Burns
http://TrainingOn.net



Hi,

I dynamicly add custom control in SelectedIndexChanged even of GridView which is firing after Page_Load. My control is not being rendered to page becouse of that (I assume). How to avoid this situation? Sample below

protected void dgrCompanies_SelectedIndexChanged(object sender, EventArgs e)
{
GoogleControl MyGoogleControl = new GoogleControl ();
PlaceHolderForMap.Controls.Add(MyGoogleControl);
}
 
T

Terry Burns

Hold on, your original post asked.
My control is not being rendered to page becouse of that (I assume).

So what is it you think isnt happening that you think should ?

--
Terry Burns
http://TrainingOn.net

Control is not positioned on webpage at all. My understanding that I can load it programmatically without putting it on webpage (one reference is set at <%@ reference
Placeholder is visible. Code below works fine for TextBox control for example but not for custom control.


No, your conrol will be rendered after PreRender which happens after this event.

Have you set your control to visible
Have you positioned your control
Have you checked the Z-Order of the control
Is the PlaceHolder visible.
Have you checked that this should appear with no data in it for example ?


--
Terry Burns
http://TrainingOn.net



Hi,

I dynamicly add custom control in SelectedIndexChanged even of GridView which is firing after Page_Load. My control is not being rendered to page becouse of that (I assume). How to avoid this situation? Sample below

protected void dgrCompanies_SelectedIndexChanged(object sender, EventArgs e)
{
GoogleControl MyGoogleControl = new GoogleControl ();
PlaceHolderForMap.Controls.Add(MyGoogleControl);
}
 
T

Teemu Keiski

Hi,

Dynamical controls would need to be added on every request. Control
instances aren't stored anywehere, and as you create them initially in code,
you are also responsible for creating them on postback (subsequently as long
as control is "in action")

FYI: http://aspnet.4guysfromrolla.com/articles/092904-1.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


Hi,

I dynamicly add custom control in SelectedIndexChanged even of GridView
which is firing after Page_Load. My control is not being rendered to page
becouse of that (I assume). How to avoid this situation? Sample below

protected void dgrCompanies_SelectedIndexChanged(object sender, EventArgs e)
{
GoogleControl MyGoogleControl = new GoogleControl ();
PlaceHolderForMap.Controls.Add(MyGoogleControl);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top