vb.net - Restrict button use on count limit -


i want make button , restrict on number of clicks far have not succeeded how far came. button

<asp:button id="btnclearsesson" runat="server" text="reset"  onclick="btnclearsesson_click" /> 

this doing

protected sub page_load(byval sender object, byval e system.eventargs) handles me.load  dim lusername string static count integer  count = count + 1  lusername = httpcontext.current.user.identity.name  if count < 10 && lusername = "admin"    btnclearsesson.visible = true    else    btnclearsesson.visible = false  end if  end sub  

so problem count starts again again , not incremented

the button when clicked must increase count , if count greater 10 stop showing button

you have declared static variable inside page load flushed every time page load

so declare global scope

static count integer protected sub page_load(byval sender object, byval e system.eventargs) handles me.load  dim lusername string   count = count + 1  lusername = httpcontext.current.user.identity.name  if count < 10 && lusername = "admin"    btnclearsesson.visible = true    else    btnclearsesson.visible = false  end if  end sub  

and 1 more thing should increase count in button click event handler not in page load.

hope helps you.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -