Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, guys:
When I use Aps.net Ajax UpdatePanel control, it seems the newly setted label text value (either on the UpdatePane.Load event or Page_load event) is not saved in the view state. Details below:

In my opinion, firstly I set the text property of label one value on the mark up html(for example "<asp:label runat="server" id="label1" text="LabelText"/>). And then in the code behind .cs file, in the event like page_load, I set the label1.text another value(label1.text="newvalue"). When the page render to the browser, the label text value should update to the newvalue.

Above case works well, but when I add one UpdatePanel control and one gridview(in the UpdatePanel template of course) which holds the paging data table, each time when I select different page, and the both Page_load and UpdatePanel load raised, but in both events, I set the label.text new string value, the rendered page only display the string set first time, no update at all.

I have two questions:
1. Asp.net Ajax control is partial post back, why the page_load event raised when I using UpdataPanel control post back.
2. What inside the view state storage? It seems the new label.text value not saved in view state.

I read "the page life cycle and view state" from http://msdn.microsoft.com/en-us/library/ms972976.aspx#viewstate_topic3; and the sequence of events is "Instantation page ---> Load view state --->Load Page --->Load UpdateLabel--->Save view state--->Render to client"

Can I understand if I use Asp.net Ajax control, the sequence events changed? Or the view state is not saved any more?
Posted
Comments
Muralikrishna8811 27-Oct-11 9:31am    
If that label within update panel then only it updates otherwise not.

In any case page_load event is must and should that is the Microsoft Architecture

make sure your label must be in update panel

1 solution

Hi,

let me tell you simple example

I've three Textbox controls and one Button in my page textbox1,textbox2,textbox3

And I place one Textbox which id is textbox1 and one Button in update panel

Now I write code in page load like

C#
//under pageload
textbox1.Text=System.Date.Now.Tostring();
textbox2.Text=System.Date.Now.Tostring();
textbox3.Text=System.Date.Now.Tostring();

And

same code in Button click event also

Then when user clicks button the client side javascript which is referred in ScriptManager sends xmlhttp request to server with some information which contains ViewState,Ids of controls which are placed in update panel
and control information which control raises the event

in this example
textbox1 and value of textbox1 to server with some other information

In server side
All code which is pageload and buttonclick events runs

finally In the Response
server only places information based on request

In this example value of textbox1 only returns to browser

In client side the javascript takecare of returned information to place particular control value.

In this example the only textbox1 updated to current time

I hope you understood what I mean

All the Best
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900