Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.Append("<div>");               
            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);
            builder.Append("Text</span></span></asp:LinkButton>");
            builder.Append("</div>");

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

The result is:

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

Any idea, why such a strnge behaviour?

share|improve this question

1 Answer 1

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;");


        cell1top.Controls.Add(txtname)
        row1top.Cells.Add(cell1top);
        tbltop.Rows.Add(row1top);

        this.Controls.Add(tbltop);

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
1  
see this :- same problem stackoverflow.com/questions/2666072/… –  Vishal_Sharepoint Aug 8 '12 at 11:16
1  
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

 
discard

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.