Is it possible to count a button? Click in the return mail

What I'm trying to do is just turn off the button after 4 clicks , but when the feedback appears, it has no number of clicks. I am trying to do this using jquery. Any suggestions.?
Correct me, if I am mistaken with asp.net, we do this by setting a static variable and increasing the number of clicks on the button.

+4
source share
5 answers

Just keep the tally in ViewState

for instance

 public int ClickCount { get { return (int)(ViewState["ClickCount"] ?? 0); } set { ViewState["ClickCount"] = value; } } 
+3
source

you can do this by storing the value in a hidden field and retrieving it through jquery. but this will not be a good solution, since anyone who has html knowledge can change the value of the hidden field to enable the button.

0
source

something like that?

 window.clicks = 0; $("#mybotton").click(function(){if(window.clicks++ >= 3)$(this).disable();}); 
0
source

Put it in jQuery

 ///count number of button click var counter = 0; function CountClicks() { counter++; if (counter > 4) { alert("disable button here."); return false; }} 

Call CountClicks on click button click

0
source

in CodeBehind create the simplest

 private static int counter = 0; 

Checking the IsPostBack property you can

  if (Page.IsPostBack) counter++; 

Where you want

  Button1.Enabled = (counter<4); 

I suggest increasing the counter in the Button1_Click event

0
source

Source: https://habr.com/ru/post/1385520/


All Articles