如何创建动态按钮属性? [英] how to create dynmaic button property?

查看:61
本文介绍了如何创建动态按钮属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:-我想创建一个动态按钮,并想在该动态按钮的属性中编写代码?
我的代码如下,但它不起作用:

question :- i want to create one dynamic button and want to write code in the property of this dynamic button?
my code is followes but it doesnt work:

Button btn = new Button();
                btn.Text = "Add As Friend!";
                btn.ID = "Button1";
                                
                
                btn.Click += new System.EventHandler(btn_Click);
//
protected void btn_Click(object sender, EventArgs e)
       {

       }


错误将出现在以下行中:


error will comes int the following line:

btn.Click += new System.EventHandler(btn_Click);



请帮我!

提前thanx



plz help me!

thanx in advance

推荐答案


对我来说很好用.
Hi ,
it work fine with me .
protected System.Web.UI.WebControls.Button btn;
protected void Page_Load(object sender, EventArgs e)
{
           btn = new Button();
            btn.Text = "Add As Friend!";
            btn.ID = "Button1";
            this.btn.Click += new System.EventHandler(btn_Click);
}
protected void btn_Click(object sender, EventArgs e)
{

}


最好的问候
M.Mitwalli


Best Regards
M.Mitwalli


形式上,此示例中显示的代码正确.问题出在其他地方,可能是在调用您在片段中显示的方法的方法中,或者您对错误的观察不正确.

您确实需要提供有关错误和异常的全面信息.如果您至少要以最低的专业水平进行工作,则不工作"不提供任何信息,也不会在问题报告中使用.

—SA
Formally, the code shown in this sample is correct. The problem is somewhere else, it could be in a method calling the method you are showing in a fragment, or your observation of the error is incorrect.

You really need to provide comprehensive information on errors and exceptions. "Does not work" is not informative and never used in issue reporting, if you want to work at least on a minimal professional level.

—SA


这篇关于如何创建动态按钮属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆