You must Sign In to post a response.
  • Category: ASP.NET

    Control looses value set in javascript function on server side event

    In javascript function I checking checkbox and setting value to label after satisfication of perticular condition.But in serverside event I am getting checkbox1.checked = false and text of label is default text of that label, not modified one.Why this is happening?How to handle that?
  • #766401

    Whether in our aspx Page is postback we canot track the client side value.

    defiantly looses value in javascript because javascript is client side script .

    Page post event firing server side so that situation page re rendering so we canot capture the client side value

    try to use server side then using ajax panel thats better for you.

    for ex : try this code

    <asp:ScriptManager ID="ScriptManager"
    runat="server" />
    <asp:UpdatePanel ID="UpdatePanel1"
    <legend>UpdatePanel content</legend>
    <!-- Other content in the panel. -->
    <%=DateTime.Now.ToString() %>
    <br />
    <asp:Button ID="Button1"
    Text="Refresh Panel"
    runat="server" />

    Name : Dotnet Developer-2015
    Email Id

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #766402
    if you change the value of this control through javascript in the client side it will not be propagated via postback in the serverside...whatever you do with javascript unless you remove readonly="true". Now there is a solution to this problem as described in the article above.

    Simply put this in the PageLoad event

    if (!IsPostBack)

    Just don't forget to remove ReadOnly="true" or Enable="false" if your intent was to disable the control from editing just use the snippet above. Don't forget to remove Enable="false" if you put it on.

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #766407

    I guess using HiddenField you can achieve your task, instead of Label control try to use hidden field that was helpful to you. Apart from the above try to overcome postback in a page by using AJAX UpdatePanel.

    <asp:UpdatePanel ID="upCancel" runat="server" UpdateMode="Always">
    <asp:ImageButton ID="btnCancelYes" OnClick="btnCancelYes_Click" runat="server" ImageUrl="~/Images/btnyes.jpg" />
    <asp:AsyncPostBackTrigger ControlID="btnCancelYes" EventName="Click" />

    Hope this will helpful to you....

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

Sign In to post your comments