在页面加载上动态创建LinkButton [英] Dynamically Create LinkButton On Page Load
本文介绍了在页面加载上动态创建LinkButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好朋友,
今天,我试过,在页面加载上动态创建Linkbutton ..
通过网络我发现了......
它需要Page_Int和事件处理程序
我的代码是:
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:
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>");
}
我的查询是这个......
1.)那怎么样?我们可以在页面加载条件上添加更多链接按钮
2.)如何从数据库中的列获取linkbutton上的值?
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?
推荐答案
你能尝试提供OnClientClick,如下所示:
Can you try providing OnClientClick like follows:
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);
}
这篇关于在页面加载上动态创建LinkButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文