Showing posts with label kept. Show all posts
Showing posts with label kept. Show all posts

Saturday, March 24, 2012

Ajax and Viewstate variables

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,

Nitin Pawar

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(ByVal senderAs Object,ByVal eAs System.EventArgs)Dim cntAs Integer = 0If Not ViewState("ClickCount")Is Nothing Then cnt =CInt(ViewState("ClickCount"))End If cnt += 1 lblClickCount.Text = cnt.ToString() ViewState("ClickCount") = cntEnd Sub

Wednesday, March 21, 2012

AJAX acting inconsistently

I have the following scenario:

Default.aspx -- start page (2 drop down lists)

I kept these 2 drop down lists under update panel ...but when i select drop down 1...it is also calling SelectedItemIndexChanged for Drop Down list 2...

When i commented out Updated Panel...then it is working properly...

How can i solve this situtation??

I phared the question in wrong way...

the thing that is happening is:

When i changed the Drop Down List 2, it is first calling SelectedItemIndexChanged of drop down list 1, then it is going to drop down 2 SelectedItemIndexChanged.

When i commented out Update panel...then it is working properly... How to tackle this situtation?