Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
C#
private void CreateLinkButton(string commandArgument, string tidshow)
        {
            string[] show = tidshow.Split('*');

            innerTableCell = new HtmlTableCell();
            System.Web.UI.HtmlControls.HtmlGenericControl createDiv =
             new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");

          //  createDiv.Style.Add(HtmlTextWriterStyle.BackgroundColor, "cyan");
            // createDiv.Style.Add(HtmlTextWriterStyle.Color, "Red");
            createDiv.Style.Add(HtmlTextWriterStyle.Height, "25px");
            createDiv.Style.Add(HtmlTextWriterStyle.Width, "150px");
            createDiv.Style.Add(HtmlTextWriterStyle.Position, "relative");
            createDiv.Style.Add(HtmlTextWriterStyle.VerticalAlign, "false");
            UpdatePanel up = new UpdatePanel();
            up.ID = "up" + tidshow;
            

          LinkButton linkButton = new LinkButton
            {
                ID = tidshow,
                Text = show[1],
                CommandArgument = commandArgument,
            };

           // linkButton.OnClientClick = "ShowPopup();";
            linkButton.Command += this.linktest_Click;
            linkButton.CausesValidation = false;
            linkButton.EnableViewState = true;
            linkButton.ToolTip = "Filling Fast";
            linkButton.Style.Add(HtmlTextWriterStyle.BorderColor, "green");
            up.ContentTemplateContainer.Controls.Add(linkButton);
            createDiv.Controls.Add(up);
            innerTableCell.Controls.Add(createDiv);
            innerTableRow.Cells.Add(innerTableCell);

        }

        protected void linktest_Click(Object sender, CommandEventArgs e)
        {
            flag = "allow";
            ViewState["isPostBackOfOutputPage"] = "yes";

            ViewState["path"] = @e.CommandArgument.ToString();

            show(e.CommandArgument.ToString());
        }
Posted
Updated 12-Nov-13 2:00am
v3
Comments
swapnil_jadhav 12-Nov-13 8:33am    
CreateLinkButton should be called during init of your page, on each postback.
So the OnInit event should look like this

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
CreateLinkButton();

}
teja sai ravi 13-Nov-13 0:38am    
thank you sir ur solution is working
teja sai ravi 12-Nov-13 23:36pm    
thanks for ur reply but my link button is creating with unique path and tidshows how can i pass these values to my different link buttons....

This is how you add an eventhandler to the button:
linkButton.Click += new EventHandler(this.linktest_Click);
 
Share this answer
 
Comments
teja sai ravi 13-Nov-13 1:44am    
thanks for ur reply sir, its working with pageinit() ...
Richard C Bishop 13-Nov-13 10:12am    
You are welcome. Did this help you or did you find another method to solve your problem?
using oninit() problem is solved.

thanks to
XML
swapnil_jadhav

<pre lang="cs">protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        CreateLinkButton();

    }</pre>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900