How to retain control value?

Posted by Balajikcp8 under ASP.NET AJAX on 6/1/2012 | Points: 10 | Views : 1394 | Status : [Member] | Replies : 1
This is my code

<asp:ScriptManager id="ScriptManager1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<asp:AsyncPostBackTrigger ControlID="CheckBox1" EventName="CheckedChanged" />
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True"
oncheckedchanged="CheckBox1_CheckedChanged" />
<asp:Label ID="Label1" runat="server" Text="Label" ViewStateMode="Enabled"></asp:Label>

<input id="Button2" onclick="call()" type="button" value="button" />

My javascript
<script language="javascript" type="text/javascript">
function call()
document.getElementById("Label1").innerHTML = "balaji";

I'm changing my label value on Button2 click event in java script. Now if i click check box, the label value goes to default one..

i can't retain label value on "AsyncPostBack"..How to retain?


Posted by: Ajay.Kalol on: 6/2/2012 [Member] Starter | Points: 25

You are updating Label value from JavaScript that is not get from code behind when you make postback.
So page has only Label's Default value in its viewstate so when control rebuilt from viewstate then its default value will displayed.

Try to change value of Label from Code behind and then see. You will find your result,

JavaScript affect only UI for display result, Value changed by JavaScript can't get from Code behind Unless you use Ajax Method or Page Method



Balajikcp8, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response