从后面的代码中更改按钮的单击值. [英] Changing the button click value from code behind.

查看:65
本文介绍了从后面的代码中更改按钮的单击值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,
在Google中进行了许多搜索之后,我来到这里希望找到答案
我想在后面的代码中将onClick =的值更改为新值"
例如:
如果在源中onClick ="Button1_click"
我想将其从后面的代码更改为
onClick ="btnclick"

我在自己的网络项目中制作了一款简单的游戏,现在被这个
卡住了

Hey there ,
After doing many searches in google I came to here hoping to find the answer
I want to change the value of onClick="to new value" in code behind
for example:
if in the source onClick="Button1_click"
I want to change it from the code behind to
onClick="btnclick"

I''m making a light game in my web-project and now stuck with this
thanks in advance.

推荐答案

分离现有的事件处理程序:
button.Click-= Button1_click;
然后分配新的事件处理程序:
按钮.单击+ = btnclick;

如果这不起作用,则意味着您正在标记中分配事件处理程序.删除该代码,并在代码后面进行分配(可以通过(IsPostBack)检查),然后放入上面的代码.试试这个,让我知道.
Detach the existing event handler:
button.Click -= Button1_click;
then assign the new event handler:
button.Click += btnclick;

If this is not working that means you are assigning the event handler in your markup. Remove that and do the assignment in code-behind maybe with a (IsPostBack) check, and then put the above piece of code. Try this and let me know.


尝试这个

公共局部类_Default:System.Web.UI.Page
{
受保护的void Page_Load(对象发送者,EventArgs e)
{
Button1.Click-= Button1_Click;
Button1.Click + = btnclick;
}
受保护的无效btnclick(对象发送者,EventArgs e)
{
Label1.Text =工作";
}
}
Try to this

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Button1.Click -= Button1_Click;
Button1.Click += btnclick;
}
protected void btnclick(object sender, EventArgs e)
{
Label1.Text = "worked";
}
}


这篇关于从后面的代码中更改按钮的单击值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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