Showing posts with label thiscontrolsadd. Show all posts
Showing posts with label thiscontrolsadd. Show all posts

Saturday, March 24, 2012

this.Controls.Add(ImageButton[i]) exception

Morning -

I am hoping somebody from this group can help me out here...

I have been trying to add an array of ImageButtons to my WebForm however I
keep getting an exception that I can't seem to find an answer for any where
on the net.

Any help in the right direction would be greatly appreciated. If more
code/source is need please let me know and I will post more.

thx -

CJ

<!-- Code here>
...
ImageButton [] ImageArray = new ImageButton[FileName.Length];
...
for (int i = 0; i < FileName.Length; i++)
{
ImageArray[i]= new ImageButton();
...
this.Controls.Add(ImageArray[i]);
}
...

<HTML>
...
<FORM id="display" method="post" runat="server">
...
</FORM>
</HTML
Exception Details: System.Web.HttpException: Control 'Preview1' of type
'ImageButton' must be placed inside a form tag with runat=server.

Stack Trace:

[HttpException (0x80004005): Control 'Preview1' of type 'ImageButton' must
be placed inside a form tag with runat=server.]
System.Web.UI.Page.VerifyRenderingInServerForm(Con trol control)
System.Web.UI.WebControls.ImageButton.AddAttribute sToRender(HtmlTextWriter
writer)
System.Web.UI.WebControls.WebControl.RenderBeginTa g(HtmlTextWriter
writer)
System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer)
System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
System.Web.UI.Control.Render(HtmlTextWriter writer)
System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
System.Web.UI.Page.ProcessRequestMain()

<end code --Hi CJ,

If you add ImageButton to form rather than page, the
ImageButton will be placed inside form tag:

HtmlForm form = (HtmlForm)this.FindControl("Form1");

//...
form.Controls.Add(ImageArray[i]);
//...

Hope it's helpful to you.

Elton Wang

elton_wang@.hotmail.com

>--Original Message--
>Morning -
>I am hoping somebody from this group can help me out
here...
>I have been trying to add an array of ImageButtons to my
WebForm however I
>keep getting an exception that I can't seem to find an
answer for any where
>on the net.
>Any help in the right direction would be greatly
appreciated. If more
>code/source is need please let me know and I will post
more.
>thx -
>CJ
><!-- Code here>
>...
>ImageButton [] ImageArray = new ImageButton
[FileName.Length];
>...
>for (int i = 0; i < FileName.Length; i++)
> {
> ImageArray[i]= new ImageButton();
> ...
> this.Controls.Add(ImageArray[i]);
> }
>...
><HTML>
>...
> <FORM id="display" method="post" runat="server">
> ...
> </FORM>
></HTML>
>Exception Details: System.Web.HttpException:
Control 'Preview1' of type
>'ImageButton' must be placed inside a form tag with
runat=server.
>Stack Trace:
>
>[HttpException (0x80004005): Control 'Preview1' of
type 'ImageButton' must
>be placed inside a form tag with runat=server.]
> System.Web.UI.Page.VerifyRenderingInServerForm(Con trol
control)
System.Web.UI.WebControls.ImageButton.AddAttribute sToRender
(HtmlTextWriter
>writer)
> System.Web.UI.WebControls.WebControl.RenderBeginTa g
(HtmlTextWriter
>writer)
> System.Web.UI.WebControls.WebControl.Render
(HtmlTextWriter writer)
> System.Web.UI.Control.RenderControl(HtmlTextWriter
writer)
> System.Web.UI.Control.RenderChildren(HtmlTextWrite r
writer)
> System.Web.UI.Control.Render(HtmlTextWriter writer)
> System.Web.UI.Control.RenderControl(HtmlTextWriter
writer)
> System.Web.UI.Page.ProcessRequestMain()
><end code -->
>
>.
Hi,

You need to give some part of the source code and the error description.
Then only we can figure out.

Prakash.C

"Elton Wang" wrote:

> Hi CJ,
> If you add ImageButton to form rather than page, the
> ImageButton will be placed inside form tag:
> HtmlForm form = (HtmlForm)this.FindControl("Form1");
> //...
> form.Controls.Add(ImageArray[i]);
> //...
> Hope it's helpful to you.
> Elton Wang
> elton_wang@.hotmail.com
> >--Original Message--
> >Morning -
> >I am hoping somebody from this group can help me out
> here...
> >I have been trying to add an array of ImageButtons to my
> WebForm however I
> >keep getting an exception that I can't seem to find an
> answer for any where
> >on the net.
> >Any help in the right direction would be greatly
> appreciated. If more
> >code/source is need please let me know and I will post
> more.
> >thx -
> >CJ
> ><!-- Code here>
> >...
> >ImageButton [] ImageArray = new ImageButton
> [FileName.Length];
> >...
> >for (int i = 0; i < FileName.Length; i++)
> > {
> > ImageArray[i]= new ImageButton();
> > ...
> > this.Controls.Add(ImageArray[i]);
> > }
> >...
> ><HTML>
> >...
> > <FORM id="display" method="post" runat="server">
> > ...
> > </FORM>
> ></HTML>
> >Exception Details: System.Web.HttpException:
> Control 'Preview1' of type
> >'ImageButton' must be placed inside a form tag with
> runat=server.
> >Stack Trace:
> >[HttpException (0x80004005): Control 'Preview1' of
> type 'ImageButton' must
> >be placed inside a form tag with runat=server.]
> > System.Web.UI.Page.VerifyRenderingInServerForm(Con trol
> control)
> System.Web.UI.WebControls.ImageButton.AddAttribute sToRender
> (HtmlTextWriter
> >writer)
> > System.Web.UI.WebControls.WebControl.RenderBeginTa g
> (HtmlTextWriter
> >writer)
> > System.Web.UI.WebControls.WebControl.Render
> (HtmlTextWriter writer)
> > System.Web.UI.Control.RenderControl(HtmlTextWriter
> writer)
> > System.Web.UI.Control.RenderChildren(HtmlTextWrite r
> writer)
> > System.Web.UI.Control.Render(HtmlTextWriter writer)
> > System.Web.UI.Control.RenderControl(HtmlTextWriter
> writer)
> > System.Web.UI.Page.ProcessRequestMain()
> ><end code -->
> >.

this.Controls.Add(Control) Does Not Add Control to child collection (this.Controls.Count =

Ok, as silly as it may sound, I have a situation where I am creating a
CompositeControl in ASP.NET 2.0, C#. I have the following code in the
CreateChildControls() method that build the control's child control
collection:

for (int i = 0; i < _menus.Count; i++)
this.Controls.Add(_menus[i]);

foreach (FloatingMenu menu in _menus)
{
Label lbl = new Label();
lbl.ID = string.Concat("GroupQ", menu.ID);
lbl.CssClass = "menuItemGroupHeader";
lbl.Text = menu.GroupName;
this.Controls.Add(lbl);

HoverMenuExtender extender = new HoverMenuExtender();
extender.ID = string.Concat("ExtenderQ", menu.ID);
extender.TargetControlID = lbl.ID;
extender.PopupControlID = menu.ID;
extender.PopupPosition = HoverMenuPopupPosition.Bottom;
this.Controls.Add(extender);
}

The amazing thing is here, that the Label control and the HoverMenuExtender
AJAX Toolkit control both get added just fine, however I added a watch on
this.Controls.Count for the line where I add my FloatingMenu control
collection, "_menus", and after each call to "this.Controls.Add(_menus[i]);"
the Count is 0, however after I add the label it's 1 and the extender it's
2.

I'm stumped.

Thanks,
ChadWhat is the value of _menus.Count before the for loop

"Chad Scharf" <chadscharf@.community.nospamwrote in message
news:%23qrSW5CEIHA.5752@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Ok, as silly as it may sound, I have a situation where I am creating a
CompositeControl in ASP.NET 2.0, C#. I have the following code in the
CreateChildControls() method that build the control's child control
collection:
>
for (int i = 0; i < _menus.Count; i++)
this.Controls.Add(_menus[i]);
>
foreach (FloatingMenu menu in _menus)
{
Label lbl = new Label();
lbl.ID = string.Concat("GroupQ", menu.ID);
lbl.CssClass = "menuItemGroupHeader";
lbl.Text = menu.GroupName;
this.Controls.Add(lbl);
>
HoverMenuExtender extender = new HoverMenuExtender();
extender.ID = string.Concat("ExtenderQ", menu.ID);
extender.TargetControlID = lbl.ID;
extender.PopupControlID = menu.ID;
extender.PopupPosition = HoverMenuPopupPosition.Bottom;
this.Controls.Add(extender);
}
>
>
The amazing thing is here, that the Label control and the
HoverMenuExtender AJAX Toolkit control both get added just fine, however I
added a watch on this.Controls.Count for the line where I add my
FloatingMenu control collection, "_menus", and after each call to
"this.Controls.Add(_menus[i]);" the Count is 0, however after I add the
label it's 1 and the extender it's 2.
>
I'm stumped.
>
Thanks,
Chad
>


_menus.Count is 2 before the loop. And the second, foreach loop adds 2
Labels and 2 HoverMenuExtenders as it should. I tried the first loop with a
foreach initially, but remembering SyncRoot issues and thought perhaps the
enumerator was breaking the Add operation, I changed it to the for loop to
no avail.

"IfThenElse" <sql_agentman@.hotmail.comwrote in message
news:%23D0oraEEIHA.6120@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

What is the value of _menus.Count before the for loop
>
>
"Chad Scharf" <chadscharf@.community.nospamwrote in message
news:%23qrSW5CEIHA.5752@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

>Ok, as silly as it may sound, I have a situation where I am creating a
>CompositeControl in ASP.NET 2.0, C#. I have the following code in the
>CreateChildControls() method that build the control's child control
>collection:
>>
>for (int i = 0; i < _menus.Count; i++)
>this.Controls.Add(_menus[i]);
>>
>foreach (FloatingMenu menu in _menus)
>{
>Label lbl = new Label();
>lbl.ID = string.Concat("GroupQ", menu.ID);
>lbl.CssClass = "menuItemGroupHeader";
>lbl.Text = menu.GroupName;
>this.Controls.Add(lbl);
>>
>HoverMenuExtender extender = new HoverMenuExtender();
>extender.ID = string.Concat("ExtenderQ", menu.ID);
>extender.TargetControlID = lbl.ID;
>extender.PopupControlID = menu.ID;
>extender.PopupPosition = HoverMenuPopupPosition.Bottom;
>this.Controls.Add(extender);
>}
>>
>>
>The amazing thing is here, that the Label control and the
>HoverMenuExtender AJAX Toolkit control both get added just fine, however
>I added a watch on this.Controls.Count for the line where I add my
>FloatingMenu control collection, "_menus", and after each call to
>"this.Controls.Add(_menus[i]);" the Count is 0, however after I add the
>label it's 1 and the extender it's 2.
>>
>I'm stumped.
>>
>Thanks,
>Chad
>>


>
>


Does anyone have any clue why this would happen? I'm still banging my head
against a wall trying to figure this out.

"Chad Scharf" <chadscharf@.community.nospamwrote in message
news:%23qrSW5CEIHA.5752@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Ok, as silly as it may sound, I have a situation where I am creating a
CompositeControl in ASP.NET 2.0, C#. I have the following code in the
CreateChildControls() method that build the control's child control
collection:
>
for (int i = 0; i < _menus.Count; i++)
this.Controls.Add(_menus[i]);
>
foreach (FloatingMenu menu in _menus)
{
Label lbl = new Label();
lbl.ID = string.Concat("GroupQ", menu.ID);
lbl.CssClass = "menuItemGroupHeader";
lbl.Text = menu.GroupName;
this.Controls.Add(lbl);
>
HoverMenuExtender extender = new HoverMenuExtender();
extender.ID = string.Concat("ExtenderQ", menu.ID);
extender.TargetControlID = lbl.ID;
extender.PopupControlID = menu.ID;
extender.PopupPosition = HoverMenuPopupPosition.Bottom;
this.Controls.Add(extender);
}
>
>
The amazing thing is here, that the Label control and the
HoverMenuExtender AJAX Toolkit control both get added just fine, however I
added a watch on this.Controls.Count for the line where I add my
FloatingMenu control collection, "_menus", and after each call to
"this.Controls.Add(_menus[i]);" the Count is 0, however after I add the
label it's 1 and the extender it's 2.
>
I'm stumped.
>
Thanks,
Chad
>

this.Controls.Add()

I am developing a series of custom controls which get
added to a parent aspx container using the instruction
this.Controls.Add( myControl ). The parent application
creates an html table dynamically, and for each table row,
adds upwards of seven custom controls per row, which are
initially hidden. Custom controls are displayed based on
buttons the user clicks on a given row. When the
application processes renders table rows in an amount
greater than thirty, the application takes over 30 seconds
to render the entire page. We have used .NET profiler and
have determined the instruction this.Controls.Add(
myCustomControl ) is where execution time is being
consumed. My custom controls are simply c-sharp classes
with a Page_Load handler. These custom classes in turn
render a series of web-based .NET controls.

Why is the instruction this.Controls.Add() performing
slow? I have 1 gig of memory on my workstation.

SteveHi Steve,

Did this problem occur with a particualr custom control? For example, when
you add it with this.Controls.Add, it run slowly? If you add 30 same custom
controls, will this problem also occur?

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Hi Luke,

Nope. The problem is apparent with all custom controls
added I've implemented. There are three main
this.Controls.Add( myControl ) calls in the top level
page_load. These calls are executed for each table row
rendered. There are thirty table rows in all. Each of the
custom controls added, may in turn nest other custom
controls which are added using this.Controls.Add(
myControl2 ). The .Net profiler has determined that these
calls are suspect and responsible for most of the
execution time. Ultimately the custom controls are
rendering a series of web controls. Now all of the custom
controls have a page_load event which gets called when the
control is added (i.e this.Controls.Add() ). Can I send
you an attachment of a sample custom control? How would I
direct an e-mail of this type using the web-client.

Steve Gagliardo

>--Original Message--
>Hi Steve,
>Did this problem occur with a particualr custom control?
For example, when
>you add it with this.Controls.Add, it run slowly? If you
add 30 same custom
>controls, will this problem also occur?
>Luke
>Microsoft Online Support
>Get Secure! www.microsoft.com/security
>(This posting is provided "AS IS", with no warranties,
and confers no
>rights.)
>.
Hi Steve,

With web-client, it is not be able to attach such a big project. To protect
your private code, I recommend you may submit a technial support incodent
for this issue. I think we need to analyst the source code of your custom
web control to find the problem. With a support incodent, this issue may be
resoved in a timely way. For detail, you may browse to:
support.microsoft.com.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

this.Controls.Add(ImageButton[i]) exception

Hi CJ,
If you add ImageButton to form rather than page, the
ImageButton will be placed inside form tag:
HtmlForm form = (HtmlForm)this.FindControl("Form1");
//...
form.Controls.Add(ImageArray[i]);
//...
Hope it's helpful to you.
Elton Wang
elton_wang@dotnet.itags.org.hotmail.com

>--Original Message--
>Morning -
>I am hoping somebody from this group can help me out
here...
>I have been trying to add an array of ImageButtons to my
WebForm however I
>keep getting an exception that I can't seem to find an
answer for any where
>on the net.
>Any help in the right direction would be greatly
appreciated. If more
>code/source is need please let me know and I will post
more.
>thx -
>CJ
><!-- Code here>
>...
>ImageButton [] ImageArray = new ImageButton
[FileName.Length];
>...
>for (int i = 0; i < FileName.Length; i++)
> {
> ImageArray[i]= new ImageButton();
> ...
> this.Controls.Add(ImageArray[i]);
> }
>...
><HTML>
>...
> <FORM id="display" method="post" runat="server">
> ...
> </FORM>
></HTML>
>Exception Details: System.Web.HttpException:
Control 'Preview1' of type
>'ImageButton' must be placed inside a form tag with
runat=server.
>Stack Trace:
>
>[HttpException (0x80004005): Control 'Preview1' of
type 'ImageButton' must
>be placed inside a form tag with runat=server.]
> System.Web.UI.Page.VerifyRenderingInServerForm(Control
control)
>
System.Web.UI.WebControls.ImageButton.AddAttributesToRender
(HtmlTextWriter
>writer)
> System.Web.UI.WebControls.WebControl.RenderBeginTag
(HtmlTextWriter
>writer)
> System.Web.UI.WebControls.WebControl.Render
(HtmlTextWriter writer)
> System.Web.UI.Control.RenderControl(HtmlTextWriter
writer)
> System.Web.UI.Control.RenderChildren(HtmlTextWriter
writer)
> System.Web.UI.Control.Render(HtmlTextWriter writer)
> System.Web.UI.Control.RenderControl(HtmlTextWriter
writer)
> System.Web.UI.Page.ProcessRequestMain()
><end code -->
>
>.
>Hi,
You need to give some part of the source code and the error description.
Then only we can figure out.
Prakash.C
"Elton Wang" wrote:

> Hi CJ,
> If you add ImageButton to form rather than page, the
> ImageButton will be placed inside form tag:
> HtmlForm form = (HtmlForm)this.FindControl("Form1");
> //...
> form.Controls.Add(ImageArray[i]);
> //...
> Hope it's helpful to you.
> Elton Wang
> elton_wang@.hotmail.com
>
> here...
> WebForm however I
> answer for any where
> appreciated. If more
> more.
> [FileName.Length];
> Control 'Preview1' of type
> runat=server.
> type 'ImageButton' must
> control)
> System.Web.UI.WebControls.ImageButton.AddAttributesToRender
> (HtmlTextWriter
> (HtmlTextWriter
> (HtmlTextWriter writer)
> writer)
> writer)
> writer)
>