Click here to Skip to main content
15,910,877 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I am stuck at very silly place..

what is happening on page load event i am trying to set a checkbox checked state =true;


auto post back of checkbox is not set .. and when i submit button again on load i am trying to set value=true after uncheck the checkbox

but its state is still unchecked

Load event of page is

C#
protected void Page_Load(object sender, EventArgs e)
   {
       this.chkMain.Attributes.Add("onclick", "EnableDisableButton(this)");
       this.chkMain.Checked = true;

   }

and

aspx page is this

XML
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">

<script type="text/javascript">
    function EnableDisableButton(obj) {

        var btnSaveID=<%=btnSave.ClientID %>;

        if(obj.checked)
        {

        document.getElementById(btnSaveID.id).value='raman';

        }
        else
         document.getElementById(btnSaveID.id).value='Save';

    }
</script>
<asp:CheckBox runat="server" ID="chkMain" Text="CheckFirst" />
<asp:Button Text="Save" ID="btnSave" runat="server" />
</asp:Content>



please suggest..
Posted
Comments
What exactly you want to do?
Raman Midha 30-Mar-14 4:34am    
i think its very clear from code.. i just want to keep checkbox checked on every postback .... but if i uncheck the checkbox and then do the postback is still in unchecked state

1 solution

Put this on your page load

C#
if (!IsPostBack)
               {
                //put your textbox argument here
               }
 
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