单击按钮时如何仅在首次调用函数 [英] How to call a function only first time if a button is clicked
问题描述
大家好,
我有一个按钮和一个函数.现在我只想在下次不想单击此函数时在一次按钮单击事件上调用此函数.
请让我知道该怎么做.
谢谢你
Mohd Wasif
Hi All,
I have a button and a function .Now I want to call this function on button click event only once next time I do not want to call this function.
Please let me know how to do it.
Thanking You
Mohd Wasif
推荐答案
int i=0;
protected void Button1_Click(object sender, EventArgs e)
{
if(i=0)
{
function()
i=1;
}
}
我的文章提供了一种非常通用的方法: ^ ].
用法非常简单,看起来像这样:
A very universal method is offered by my article: Wish You Were Here… Only Once[^].
The usage is unusually simple and looks like this:
if (FirstTime.Here)
ThisWillHappenButOnlyOnce();
其中FirstTime.Here
是我类的静态方法,而ThisWillHappenButOnlyOnce
是您要在每次运行时仅调用一次的方法(或任何东西,某些块).
警告!此功能的实现具有良好的性能,非常可靠且通用,但是...了解其工作原理可能会令人费解. :-)
请尝试.
您可以在以任何语言编写的任何类型的.NET项目中使用我的库.
where FirstTime.Here
is the static method of my class and ThisWillHappenButOnlyOnce
is your method (or anything, some block) you want to call only once per you runtime.
Warning! Implementation of this feature has good performance, very reliable and universal but… understanding of how it works can be a mind-bending. :-)
Please try.
You can use my library in any type of .NET project written in any language.
使用标志可以轻松完成.
Hi,
it can be done easily using a flag.
int i=0;//it is set in the !ispostback
protected void Button1_Click(object sender, EventArgs e)
{
if(i=0)
{
function()//call our function
i=1;
}
}
试试这个.如果没有疑问,请对此发表评论.
try this.if nay doubt pls comment on this.
这篇关于单击按钮时如何仅在首次调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!