Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends,
Today , I have tried, to Dynamically create Linkbutton, on Page Load..
Through net I have found out that...
It Requires Page_Int and Event handler
My Code is:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class linkpage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    void Page_Init(object sender, EventArgs e)
    {
        Label myLabel = new Label();
        myLabel.Text = "Test this one out...";
        this.form1.Controls.Add(myLabel);

        LinkButton link = new LinkButton();
        link.Text = "lnk";
        link.ID = "LinkButton";
        link.Click += new System.EventHandler(link_Click);
        this.form1.Controls.Add(link);
    }
    protected void link_Click(object sender, EventArgs e)
    {
        ClientScript.RegisterClientScriptBlock(this.GetType(), "lnk",
          "<script type = 'text/javascript'>alert('LinkButton Clicked');</script>");
    }


My Query is this...
1.)That how? we can Add More Linkbutton on Page load Condition
2.)How to Fetch value on linkbutton from column in Database?
Posted
Updated 3-Mar-13 3:10am
v2
Comments
[no name] 3-Mar-13 9:10am    
1. Huh? What? Can you rephrase your question to something that makes some sense?
2. You connect to your database and query data.

You might want to get your keyboard looked at, There Appears To Be something Wrong With the Shift Key Sometimes.
Ankit_Sharma1987 3-Mar-13 9:19am    
Sir, I want Linkbutton, to be generated, on page load condition, and, i want value bind in that linkbutton dynamically, from single, column of table content!!
Then in page load event, just go to database and fetch the data and bind it...

Are you facing any problems ?

1 solution

Can you try providing OnClientClick like follows:

C#
protected void Page_Load(object sender, EventArgs e)
   {
       LinkButton lb = new LinkButton();
       lb.ID = "lb1";
       lb.OnClientClick = "alert('LinkButton Clicked');";
       lb.Text = "click me";

       this.form1.Controls.Add(lb);
   }
 
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