SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an issue when i try to render the linkbutton with image and text it isn't rendered correctly. I render it from a servercontrol in method OnLoad. And I do not understand why, maybe someone knows the problem.

Here is the code:

        StringBuilder builder = new StringBuilder(); 
            builder.AppendFormat("<asp:LinkButton runat='server' id='someid_{0}' OnClientClick='{0}_perfrom();'>", this.ClientID);
            builder.AppendFormat("<span><span><img style='border:0' id='SomePic_{0}' src='/_layouts/images/mypict.png' />", this.ClientID);

            this.Controls.add(new LiteralControl(builder.ToString()));

The result is:

  <asp:linkbutton id="" runat="server" /> //here by some reason the tag is closed
    <img ....>
    </asp:linkbutton /> //and also here

Any idea, why such a strnge behaviour?

share|improve this question

this is not the way u can add server side control in code-behiend

you can do something like this

        TextBox txtname = new TextBox();
        HtmlTable tbltop = new HtmlTable();
        HtmlTableRow row1top = new HtmlTableRow();
        HtmlTableCell cell1top = new HtmlTableCell();
        // apply style like that
        cell1top.Attributes.Add("Style", "color:#1C1156;font-size:30px;font-weight:bold;");



you can do same thing using div also.

share|improve this answer
What is this? Sorry but this is far from what i'm looking for. just adding a table to page ... why? – Shkipper Aug 8 '12 at 10:50
look code i am adding textbox a server control in table cell and then add table in page – Vishal_Sharepoint Aug 8 '12 at 10:51
why -1? please describe – Vishal_Sharepoint Aug 8 '12 at 10:52
see this :- same problem… – Vishal_Sharepoint Aug 8 '12 at 11:16
Shkipper: He is saying is that you cannot add server side controls like that, and its probably not far from what you are looking for :) – Anders Aune Aug 8 '12 at 13:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.