following codes shows how to do that properly -
LinkButton but = new LinkButton();
but.Text = "csharp";
but.Attributes.Add("modid", ModuleId.ToString());
but.ID = ModuleId.ToString();//used dnn module id
but.BorderColor = Color.Black;
but.BackColor = Color.White;
but.BorderWidth = Unit.Pixel(1);
but.CssClass = "Mitsol_Paging_Button";
but.Style.Add("margin-left", "3px");
but.Style.Add("padding", "2px 3px 2px 3px");
but.OnClientClick = "MitsolPageIndex_Click(this);";
but.Click += new EventHandler(Page_Command);
pagePlaceholder.Controls.Add(but);
here pagePlaceholder is a PlaceHolder control and Page_Command
is the event handler registered.It will be look like -
protected void Page_Command(object sender, EventArgs e)
{
//code goes here
}