ASp.net Dynamic link buton
<p>I am creating a dynamic link during page_init even and binding onclick to a link button.On click of dynamic link is able post back but it is not raising a onclick eveent (hitting a on click event in debug mode). Page postback and shows up a blank page without triggering a event.Plese can anyone tell what i am doing wrong in the following code.I am using vs2005(ASp.Net 2.0).Please see first  switch case where i am dynamically creating a link button.</p>

<p>public partial class ChooseRole : System.Web.UI.Page
{
    public Int32 ismId;
   public DataTable UserCredentialsDT;
    public DataTable dsUserDetails = null;
    public String strPage = "";
    protected System.Web.UI.WebControls.LinkButton lnkAdmin;</p>

<pre><code>//protected System.Web.UI.WebControls.PlaceHolder PlaceHolderRoles;

protected void Page_Init(object sender, EventArgs e)
{
    if (Session[PresentationConstant.USERCREDENTIALS] != null)
    {
        dsUserDetails = (DataTable)Session[PresentationConstant.USERCREDENTIALS];
        ismId = Convert.ToInt32(dsUserDetails.Rows[0][0].ToString());
    }

    Helper.validateRoleAuthentication(PresentationConstant.PAGE_CHOOSEROLE);
    if (!IsPostBack)
    {            
        if (Session[PresentationConstant.USERCREDENTIALS] != null)
        {
            UserCredentialsDT = (DataTable)Session[PresentationConstant.USERCREDENTIALS];

            //Sorting the roles
            DataView v = UserCredentialsDT.DefaultView;
            v.Sort = "roleName";
            UserCredentialsDT = v.ToTable();

            Int32 ismId = Convert.ToInt32(UserCredentialsDT.Rows[0][0].ToString());

            for (int i = 0; i &lt; UserCredentialsDT.Rows.Count; i++)
            {

                switch (Convert.ToInt32(UserCredentialsDT.Rows[i]["RoleId"]))
                {
                    case (int)Helper.UserRole.Administrator:

                        //Session[AppConstants.ROLEID] = UserCredentialsDT.Rows[i]["RoleId"];
                         //LinkButton link = new LinkButton();
                         //{
                         //    link.Text = "Test&lt; /br&gt;";
                         //    link.ID = "TestButton";
                         //    link.Click += new EventHandler(TestClicked);


                         //}
                         //PlaceHolderRoles.Controls.Add(link);
                        lnkAdmin = new LinkButton();
                        lnkAdmin.EnableViewState = true;
                        lnkAdmin.Text = "Administrator" + "&lt;br /&gt;";
                        lnkAdmin.ID = "lnkAdmin";

                        this.lnkAdmin.Click += new EventHandler(this.lnkAdmin_Click);
                        this.PlaceHolderRoles.Controls.Add(lnkAdmin);


                        //lnkAdmin.Visible = true;

                        break;


                    case (int)Helper.UserRole.KeyHolder:
                        Session[AppConstants.ROLEID] = UserCredentialsDT.Rows[i]["RoleId"];
                        String strPage;
                        LinkButton lnkSM = new LinkButton();
                        lnkSM.EnableViewState = true;
                        lnkSM.Text = "Manager / Key Holder" + "&lt;br /&gt;";
                        lnkSM.ID = "lnkSM" + i.ToString();
                        PlaceHolderRoles.Controls.Add(lnkSM);
                        lnkSM.Visible = true;
                        strPage = GetStoresForStoreManager_Table(ismId);
                        if (!String.IsNullOrEmpty(strPage))
                        {
                            lnkSM.PostBackUrl = strPage;
                        }
                        break;

                    case (int)Helper.UserRole.DistrictManager:
                        Session[AppConstants.ROLEID] = UserCredentialsDT.Rows[i]["RoleId"];
                        LinkButton lnkDM = new LinkButton();
                        lnkDM.EnableViewState = true;
                        lnkDM.Text = "District Manager" + "&lt;br /&gt;";
                        lnkDM.ID = "lnkDM" + i.ToString();
                        PlaceHolderRoles.Controls.Add(lnkDM);
                        lnkDM.Visible = true;
                        lnkDM.PostBackUrl = PresentationConstant.ASPX_DMREPORTS;
                        break;

                    case (int)Helper.UserRole.ARD:
                        Session[AppConstants.ROLEID] = UserCredentialsDT.Rows[i]["RoleId"];
                        LinkButton lnkARD = new LinkButton();
                        lnkARD.EnableViewState = true;
                        lnkARD.Text = "ARD" + "&lt;br /&gt;";
                        lnkARD.ID = "lnkARD" + i.ToString();
                        PlaceHolderRoles.Controls.Add(lnkARD);
                        lnkARD.Visible = true;
                        lnkARD.PostBackUrl = PresentationConstant.ASPX_ARDREPORTS;
                        break;

                    case (int)Helper.UserRole.TeamAdvisor:
                        Session[AppConstants.ROLEID] = UserCredentialsDT.Rows[i]["RoleId"];
                        LinkButton lnkTeamAdvisor = new LinkButton();
                        lnkTeamAdvisor.EnableViewState = true;
                        lnkTeamAdvisor.Text = "Team Advisor" + "&lt;br /&gt;";
                        lnkTeamAdvisor.ID = "lnkTeamAdvisor" + i.ToString();
                        PlaceHolderRoles.Controls.Add(lnkTeamAdvisor);
                        lnkTeamAdvisor.Visible = true;
                        lnkTeamAdvisor.PostBackUrl = PresentationConstant.ASPX_DMREPORTS;
                        break;

                    case (int)Helper.UserRole.RPC:
                        Session[AppConstants.ROLEID] = UserCredentialsDT.Rows[i]["RoleId"];
                        LinkButton lnkRPC = new LinkButton();
                        lnkRPC.EnableViewState = true;
                        lnkRPC.Text = "RPC" + "&lt;br /&gt;";
                        lnkRPC.ID = "lnkRPC" + i.ToString();
                        PlaceHolderRoles.Controls.Add(lnkRPC);
                        lnkRPC.Visible = true;
                        lnkRPC.PostBackUrl = PresentationConstant.ASPX_ARDREPORTS;
                        break;

                    case (int)Helper.UserRole.RegionalManager:
                        Session[AppConstants.ROLEID] = UserCredentialsDT.Rows[i]["RoleId"];
                        LinkButton lnkRegionalManager = new LinkButton();
                        lnkRegionalManager.EnableViewState = true;
                        lnkRegionalManager.Text = "Regional Manager" + "&lt;br /&gt;";
                        lnkRegionalManager.ID = "lnkRegionalManager" + i.ToString();
                        PlaceHolderRoles.Controls.Add(lnkRegionalManager);
                        lnkRegionalManager.Visible = true;
                        lnkRegionalManager.PostBackUrl = PresentationConstant.ASPX_RMREPORTS;
                        break;

                    case (int)Helper.UserRole.MerchAdmin:
                        Session[AppConstants.ROLEID] = UserCredentialsDT.Rows[i]["RoleId"];
                        LinkButton lnkMerchAdmin = new LinkButton();
                        lnkMerchAdmin.EnableViewState = true;
                        lnkMerchAdmin.Text = "Merch Admin" + "&lt;br /&gt;";
                        lnkMerchAdmin.ID = "lnkMerchAdmin" + i.ToString();
                        PlaceHolderRoles.Controls.Add(lnkMerchAdmin);
                        lnkMerchAdmin.Visible = true;
                        lnkMerchAdmin.PostBackUrl = PresentationConstant.ASPX_MERCHANDISINGADMIN;
                        break;

                    default:
                        ClientScript.RegisterStartupScript(this.GetType(), "msg", "&lt;script type=\"text/javascript\"&gt; alert('Invalid Role.');&lt;/script&gt;");
                        break;
                }

            }
        }
    }
}
</code></pre>

<p>private String GetStoresForStoreManager_Table(Int32 iStoreManagerId)
    {
        String strDestinationPage = String.Empty;
        String strStoreNo = String.Empty;
        String strStoretypeId = String.Empty;</p>

<pre><code>    String strStoretype = String.Empty;
    DataTable dtStoreDetails = null;

    StoreBL objStoreBL = new StoreBL();
    dtStoreDetails = objStoreBL.GetStoresForStoreManager_Table(iStoreManagerId);

    if (dtStoreDetails.Rows.Count != 0)
    {
        if (dtStoreDetails.Rows.Count &gt; 1)
        {
            strDestinationPage = PresentationConstant.ASPX_CHOOSESTORE;
        }
        else
        {
            strStoreNo = dtStoreDetails.Rows[0][AppConstants.STORENO].ToString();
            strStoretypeId = dtStoreDetails.Rows[0][AppConstants.ID].ToString();
            if (dtStoreDetails.Rows[0][AppConstants.ISRETAIL].ToString().ToLower() == "true")
            {
                strStoretype = DBConstants.RETAIL;
            }
            else
            {
                strStoretype = DBConstants.SandR;
            }
            Session.Add(AppConstants.STORENO, strStoreNo);
            Session.Add(AppConstants.STORETYPEID, strStoretypeId);
            Session.Add(AppConstants.STORETYPE, strStoretype);
            strDestinationPage = PresentationConstant.ASPX_STOREMAIN;
        }
    }
    else
    {
        ClientScript.RegisterStartupScript(this.GetType(), "msg", "&lt;script type=\"text/javascript\"&gt; alert('You are not associated with any store.');window.location = 'SprintLogin.aspx';&lt;/script&gt;");
    }
    return strDestinationPage;

}
protected void lnkAdmin_Click(object sender, System.EventArgs e)
{
    Response.Redirect(PresentationConstant.ASPX_MERCHANDISINGADMIN);
}
</code></pre>
