两个动作的一个按钮 [英] One button for two actions
问题描述
很好的感觉!
我在页面上有两个链接:编辑和添加以及一个按钮提交。
当我点击它编辑时,mu按钮改变了文本编辑,点击另一个链接后更改为添加
我不想让我的按钮功能两个动作:编辑和添加。什么我必须发送按钮,在button_click()的主体之后抓住它和meke tru条件?
所以我可以检查它如何:
button_click(){
if (BtnAct.text == 添加){
this .Add();
} 其他 {
此 .Edit();
}
}
但这是丑陋的代码
我认为检查文本属性真是个坏主意。
你在什么条件下更改文本???您可以使用相同的条件来更改服务器端标志,例如布尔类型isAddButton。使其成为真/假并使用它而不是使用客户端控件属性。
:):)
制作一个枚举变量如
public Enum Action
{
Add,Edit
};
制作一个公共财产,如
public Action EnumAction
{
get;
设定;
}
现在当你想要动作添加然后简单地分配EnumAction = Action.Add
和当你想要动作编辑然后简单地确定EnumAction = Action.Edit
的值并在你的按钮点击事件中检查...
Good morging!
I have two link at page: edit and add and one button Submit.
When i click it edit, mu button changes text on "Edit", and changes to "Add" when click another link
I want no make that my button function two actions: edit and add. What i must to send button, that after in body of button_click() catch it and meke tru condition?
So i can check it how as:
button_click () {
if (BtnAct.text == "Add") {
this.Add();
} else {
this.Edit();
}
}
But it is ugly code
I think checking the text property is really a bad idea.
On what condition you are changing the text??? You may use the same condition to alter a sever side flag let say a boolean type isAddButton. Make it true/false and use it rather than using client side control properties.
:):)
make one Enum variable like
public Enum Action { Add, Edit };
make one public property of it like
public Action EnumAction { get; set; }
now when u want to make action "add" then simply assing the value of EnumAction = Action.Add
and when u want to make action "edit" then simply assing the value of EnumAction = Action.Edit
and check it at your button click event...
这篇关于两个动作的一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!