0

I created a dynamic link button, which needs to be inserted in a StringBuilder to not ruin the design of my aspx page.

So here's a "part" of my code where I need to insert my LinkButton:

design.Append("<h3>");
NewAddToCart(); //This is where my linkbutton should be inserted 
design.Append("</h3></div>");

My NewAddToCart() is constructed on the following code:

private void NewAddToCart()
{
    LinkButton lbtnAddtoCart = new LinkButton();
    lbtnAddtoCart.ID = "lbtnCart" + i;
    lbtnAddtoCart.CommandArgument = i.ToString();
    lbtnAddtoCart.CssClass = "glyphicon glyphicon-shopping-cart pull-right";
    lbtnAddtoCart.Click+=lbtnAddtoCart_Click;

    using (StringWriter sw = new StringWriter())
    {
        using (HtmlTextWriter html = new HtmlTextWriter(sw))
        {
            lbtnAddtoCart.RenderControl(html);
        }
    }
}
INDIA IT TECH
  • 1,902
  • 4
  • 12
  • 25
JC Borlagdan
  • 3,318
  • 5
  • 28
  • 51
  • 1
    You need to return the rendered string something like `return sw.ToString()`. Then, replace `NewAddToCart();` to `design.Append(NewAddToCart());` – Mosh Feu Mar 27 '16 at 06:41
  • oh i just did it. thanks.. but my problem is that it doesn't trigger the click event. but i'll find some solution. thanks for the help sir @MoshFeu – JC Borlagdan Mar 27 '16 at 11:00
  • did you find the solution? i tried to do this tooo – asmasyakirah Dec 23 '19 at 06:11

0 Answers0