This is a discussion on Ajax and Viewstate variables within the C# Programming forums, part of the Software Development category; Hello Everyone, I wanted to keep a counter for the page, which will increment or decrement based on button clicks. ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hello Everyone, I wanted to keep a counter for the page, which will increment or decrement based on button clicks. These buttons are kept in UpdatePanel so not page refresh happens. I decided to use viewstate variable as counter, I am initializing that variable to 0 for the first call. but I found that for every click I have to initialize the viewstate variable as it is not maintained across Ajax request calls,. Is there any workaround for this? Thanks in advance, S.Balasubramanian.. |
| Sponsored Links |
| |||
| Following works just fine for me... <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" /> <asp:UpdatePanel ID="UpdatePAnel1" runat="server"> <ContentTemplate> <asp:Label ID="lblClickCount" runat="server" Text="0" /> <asp:Button ID="Button1" Text="Add counter" runat="server" OnClick="Button1_Click" /> </ContentTemplate> </asp:UpdatePanel> Protected Sub Button1_Click(Object sender , System.EventArg e) { int cnt= 0; if( ViewState["ClickCount"] != null) { cnt = ViewState["ClickCount"]; } cnt += 1; lblClickCount.Text = cnt.ToString(); ViewState["ClickCount"] = cnt }
__________________ The OXYGEN Delivers edgy, intelligent Technology to all... |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to use ajax in asp.net and how to install ajax in my system | vel.m8 | ASP and ASP.NET Programming | 5 | 04-08-2008 08:55 PM |
| Is any drawbacks in using VIewState["key"] in forms | kingmaker | C# Programming | 1 | 08-11-2007 04:59 AM |
| How to increase viewstate variable in asp .net? | oxygen | ASP and ASP.NET Programming | 1 | 07-30-2007 09:15 AM |
| how can i disable teh viewstate in asp .net application ? | kingmaker | ASP and ASP.NET Programming | 1 | 07-20-2007 06:30 AM |
| When during the page processing cycle is ViewState available? | prasath | ASP and ASP.NET Programming | 1 | 07-19-2007 03:29 AM |