Congratulations to all monthly winners of May 2013 !!! They have won INR 2900 cash and INR 27497 worth prize.
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 7129 |  Welcome, Guest!   Register  Login
 Home > Forums > ASP.NET AJAX > How to retain control value? ...
Balajikcp8

How to retain control value?

Replies: 1 | Posted by: Balajikcp8 on 6/1/2012 | Category: ASP.NET AJAX Forums | Views: 506 | Status: [Member] | Points: 10  


This is my code

<asp:ScriptManager id="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="CheckBox1" EventName="CheckedChanged" />
</Triggers>
<ContentTemplate>
<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" />
</ContentTemplate>
</asp:UpdatePanel>

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

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?


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Ajay.Kalol
Ajay.Kalol  
Posted on: 6/2/2012 6:52:35 AM
Level: Starter | Status: [Member] | 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


Enjoy...

http://ajaypatelfromsanthal.blogspot.in

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

Reply - Please login to reply


Click here to login & reply

Found interesting? Add this to:


 Latest Posts

Write New Post | More ...

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 6/20/2013 12:58:05 AM