我在vs2005里开发一个wap页面,想在页面上动态生成一个控件,但是用如下代码以后,页面上的确有个link,但是点击以后无法进入common_click事件.请问该如何来绑定一个服务器端的控件的click事件 protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Command c1 = new Command();
c1.Text = "aaa";
c1.Format = CommandFormat.Link;
c1.CommandArgument = "http://www.baidu.com";
c1.Click += (new EventHandler(common_click));
Form1.Controls.AddAt(0, c1);
}
} protected void common_click(object sender, EventArgs e)
{
Command c1 = new Command();
c1 = (Command)sender;
string url = c1.CommandArgument;
Response.Redirect(url);
}
{
if (!IsPostBack)
{
Command c1 = new Command();
c1.Text = "aaa";
c1.Format = CommandFormat.Link;
c1.CommandArgument = "http://www.baidu.com";
c1.Click += (new EventHandler(common_click));
Form1.Controls.AddAt(0, c1);
}
} protected void common_click(object sender, EventArgs e)
{
Command c1 = new Command();
c1 = (Command)sender;
string url = c1.CommandArgument;
Response.Redirect(url);
}
跟这个帖子差不多
{
//new 一个Button控件。
Button button = new Button(); //为此button控件添加属性ID和ID的值为Button1。
button.Attributes.Add("ID", "Button1"); //为此button控件添加属性,设button为服务器控件。
button.Attributes.Add("runat", "server"); //使用Text属性来指定或确定在Button控件中显示的标题
button.Text = "Click me"; //为button控件添加Click事件。
button.Click += new EventHandler(this.Button1_Click); //把button控件load到aspx的PlaceHolder控件里。
this.PlaceHolder1.Controls.Add(button);
} //实现Button1_Click事件
private void Button1_Click(object sender, EventArgs e)
{
Insus.NET.InsusJsUtility js = new Insus.NET.InsusJsUtility();
js.JsAlert("'Click me' 铵钮被点击,事件已经产生。");
}
是不一样的!
是不一样的!!
是不一样的!!!