generalproblem:Thanks Bharath for answer. I have tested it and it is not working. But I have a doubt like when the page first gets loaded var count will be initialized to zero. once user submits it and again at a later point of time if he required to submit again what will be the count?
Hi,
After postback, the page will be processde and then regenerated, so the value of the "counter" will be zero again.
The article provided by Yasser is fairly useful when you want to prevent the users from submitting a form twice when the page being processed.
If you want to allow users to click the button only once, that means the button is not accessible even after the first processing, you can use a session variable as a counter like this:
Global.asax:
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Session["counter"] = 0;
}
submit page:
protected void Button1_Click(object sender, ImageClickEventArgs e)
{
if (Session["counter"] != null && (int)(Session["counter"]) == 0)
{
// logic code
Session["counter"] = (int)Session["counter"] + 1;
ImageButton1.Enabled = false;
}
}
Have a nice day!