Hi,<BR><BR>I have a problem with the simplest code imaginable, and it's driving me nuts that I can't work out what's going wrong!<BR><BR>All I want is two buttons, one that increments a counter and prints the result on the screen, while the other button decrements the same counter and prints the result on the screen.<BR><BR>As far as I can see, the code below should do just that - but what actually happens is that each button increments/decrements the counter variable ONCE ONLY, and further clicks on the button DO NOTHING AT ALL!!!<BR><BR>Why do the buttons seem to work once only????<BR><BR>HELP!!<BR><BR>************************************************** **************<BR> THE CODE:<BR>************************************************** **************<BR><BR><BR><%@ Page Language="VB" Debug="true" %><BR><BR><script runat="server" ><BR><BR> Dim iCounter as Integer<BR><BR> Sub Page_Load(obj as Object, e as EventArgs)<BR> if iCounter = "" then<BR> iCounter = 1<BR> Response.Write("On Page_Load, iCounter has been set to " & iCounter & "<BR>")<BR> end if<BR> end sub<BR> <BR> Sub Up(obj as Object, e as EventArgs)<BR> iCounter = iCounter + 1<BR> Response.Write("Having just incremented iCounter, it is now set to " & iCounter & "<BR>")<BR> end Sub<BR> <BR> Sub Down(obj as Object, e as EventArgs)<BR> iCounter = iCounter - 1<BR> Response.Write("Having just decremented iCounter, it is now set to " & iCounter & "<BR>")<BR> end Sub<BR><BR><BR></script><BR><BR><html><body><BR><BR><form runat="server" ><BR><BR> <asp:Button runat="server" id="btUp" Text="Up" OnClick="Up" /><BR> <asp:Button runat="server" id="btDown" Text="Down" OnClick="Down" /><BR><BR></form><BR><BR><BR></body></html>First Thing Web is state less, and your variable iCounter dies whenever that page life expires. <BR>in this case you can use hidden text box to store variable value of ICounter. your code would work then.<BR>Hi <BR> I have made few changes to your code so as to maintain state of application <BR><BR>************************************************** ***************<BR>Code<BR>************************************************** ***************<BR><BR><%@ Page Language="VB" Debug="true" %><BR><script runat="server"><BR>Sub Page_Load(obj as Object, e as EventArgs)<BR><BR>if txtcounter.text = "" then<BR> txtcounter.text = 1<BR> Response.Write("On Page_Load, iCounter has been set to " & txtcounter.text & " ")<BR>end if<BR>end sub<BR><BR>Sub Up(obj as Object, e as EventArgs)<BR> txtcounter.text = cint(txtcounter.text) + 1<BR> Response.Write("Having just incremented iCounter, it is now set to " & txtcounter.text & " ")<BR><BR>end Sub<BR><BR>Sub Down(obj as Object, e as EventArgs)<BR> txtcounter.text = cint(txtcounter.text) - 1<BR> Response.Write("Having just decremented iCounter, it is now set to " & txtcounter.text & " ")<BR>end Sub<BR><BR><BR></script><BR><html><BR> <body><BR> <form runat="server" ID="Form1"><BR> <asp:Button runat="server" id="btUp" Text="Up" OnClick="Up" /><BR> <asp:Button runat="server" id="btDown" Text="Down" OnClick="Down" /><BR> <asp:TextBox Runat="server" ID="txtcounter" visible="False"></asp:TextBox><BR> </form><BR> </body><BR></html>Hi, there!!!<BR>I think it should solve, don't???<BR>Well, it will seem not to work at first time, but what occurs is that the pageload with non-postback is called two times: the first when page loads and the second when you first submits the form... try to improve it and make contact if you can't...<BR><BR><%@ Page Language="VB" Debug="true" %> <BR><BR><script runat="server"> <BR><BR>Sub Page_Load(obj as Object, e as EventArgs) <BR> If Not IsPostBack Then<BR> iCounter.Value = http://aspmessageboard.com/archive/index.php/1<BR> Response.Write("On Page_Load, iCounter has been set to " & iCounter.Value & ".") <BR> End If<BR>End Sub<BR><BR>Sub Up(obj as Object, e as EventArgs) <BR>iCounter.Value = iCounter.Value + 1 <BR>Response.Write("Having just incremented iCounter.Value, it is now set to " & iCounter.Value & ".") <BR>end Sub <BR><BR>Sub Down(obj as Object, e as EventArgs) <BR>iCounter.Value = iCounter.Value - 1 <BR>Response.Write("Having just decremented iCounter.Value, it is now set to " & iCounter.Value & ".") <BR>end Sub<BR><BR><BR></script> <BR><BR><html><body> <BR><BR><form runat="server"> <BR><BR><asp:Button runat="server" id="btUp" Text="Up" OnClick="Up" /> <BR><asp:Button runat="server" id="btDown" Text="Down" OnClick="Down" /> <BR><input type=hidden runat=server id=iCounter value=0><BR><BR></form> <BR><BR><BR></body></html>Thanks for your help, code is now working and the world seems a better place!<BR><BR>JON