开发者

Problem adding control using AddAt method [ASP.NET]

On my page I have the following Image control.

    <asp:Image ID="Image1" ImageUrl="~/images/icons/returnarrow.gif" runat="server" />

Then on Page_Load I am doing the following.

    Image1.Controls.AddAt(1, new LiteralControl("ChildControl2"));

So what this should do (theoretically) is add a new LiteralControl next to the image. But it doesn't. However, If I change the index to 0 and the Image to a GridView con开发者_开发技巧trol it works.

What am I doing wrong?


Don't modify the Controls collection. Use a PlaceHolder instead.


I don't think so Image1.Controls.AddAt will add any control next to Image control because Image1.Controls is a collection of child controls of Image1, may be this.Controls.AddAt will work


You should be trying to embed another control in an image. Use a PlaceHolder as the parent container, and add the Image and Literal to the PlaceHolder.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜