Ok here goes. Why I'm creating a button inside a dynamically created table is beyond scope, but that's the context. Here's the code portion:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
public void MakeTable(object sender, EventArgs e)
{
HtmlTableRow rownp = new HtmlTableRow();
HtmlTableCell cellnp = new HtmlTableCell();
//THE DYNAMIC BUTTON IS HERE **************************************
Button bt = new Button();
bt.Text = "Click Me";
bt.Click += new EventHandler(bt_Click);
cellnp.Controls.Add(bt);
rownp.Controls.Add(cellnp);
TheTable.Rows.Add(rownp);
}
protected void Page_Load(object sender, EventArgs e)
{
}
void bt_Click(object sender, EventArgs e)
{
lbl1.Text = "Hello";
}
}
And the non-code portion. The static "lbl1" label is created in here. A staticaly created button triggers the MakeTable procedure above which contains the dynamic button "bt" and it's event assignment which will make "lbl1" say "hello" ... obviously that's not what the intended website will do... I'm testing the idea of dynamically created buttons in a dynamic table.
Code:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Button ID="btMakeTable" Text="Make Table" OnClick="MakeTable" runat="server" />
<asp:Label ID="lbl1" Text="No text yet" runat="server" />
<table id="TheTable" border="0" cellpadding="0" cellspacing="0" runat="server" />
</asp:Content>
Cheers