Solved

Checkbox event handler not working

Posted on 2010-11-13
4
736 Views
Last Modified: 2012-05-10
Not sure why, but my checkbox is not doing anything when checked, even though I have the code set to do something. See code below.
<asp:Label ID="lblNPC" runat="server" Text="Non-Public Contact Information" 
        AssociatedControlID="pnlNonPublicContact" CssClass="subheader" 
        Width="305px"></asp:Label>
    <asp:Panel ID="pnlNonPublicContact" runat="server" BorderStyle="None" 
        CssClass="panels">
        <p class="label_checkbox_pair">
            <asp:CheckBox ID="chkMSame" runat="server" CssClass="black12Bold" TabIndex="11" 
                Text="Address information is the Same As Above" 
                oncheckedchanged="chkMSame_CheckedChanged" />
        </p>
<div id="lineup">
     <p>
     <asp:Label ID="lblMAddress" runat="server" Text="Mailing Address" 
            AssociatedControlID="txtMAddress"></asp:Label>
    <asp:TextBox ID="txtMAddress" runat="server" TabIndex="12" Text=""></asp:TextBox></p>
    <p>
        <asp:Label ID="lblMCity" runat="server" AssociatedControlID="txtMCity" 
            Text="City"></asp:Label>
        <asp:TextBox ID="txtMCity" runat="server" TabIndex="13" Text=""></asp:TextBox>
    </p>
    <p>
        <asp:Label ID="lblMState" runat="server" AssociatedControlID="ddlMState" 
            Text="State"></asp:Label>
        <asp:DropDownList ID="ddlMState" runat="server" TabIndex="14" DataSourceID="dsStates"
               DataTextField="LIST_ITEM_NAME" DataValueField="LIST_ID" AppendDataBoundItems="True" 
               AutoPostBack="True">
            <asp:ListItem Text="" Value="0" />
        </asp:DropDownList>
    </p>
    <p>
        <asp:Label ID="lblMZip" runat="server" AssociatedControlID="txtMZip" 
            Text="Zip Code"></asp:Label>
        <asp:TextBox ID="txtMZip" runat="server" TabIndex="15" Text=""></asp:TextBox>
    </p>
    <p>
        <asp:Label ID="lblExecDir" runat="server" AssociatedControlID="txtExecDir" 
            Text="Executive Director"></asp:Label>
        <asp:TextBox ID="txtExecDir" runat="server" TabIndex="16" Text=""></asp:TextBox>
    </p>
    <p>
        <asp:Label ID="lblEDPhone" runat="server" AssociatedControlID="txtEDPhone" 
            Text="Executive Director Phone"></asp:Label>
        <asp:TextBox ID="txtEDPhone" runat="server" TabIndex="17" Text=""></asp:TextBox>
    </p>
    <p>
        <asp:Label ID="lblContact" runat="server" AssociatedControlID="txtContact" 
            Text="Contact Person"></asp:Label>
        <asp:TextBox ID="txtContact" runat="server" TabIndex="18" Text=""></asp:TextBox>
    </p>
        <p>
            <asp:Label ID="lblContactTitle" runat="server" 
                AssociatedControlID="txtContactTitle" 
                Text="Contact Person Title"></asp:Label>
            <asp:TextBox ID="txtContactTitle" runat="server" TabIndex="19" Text=""></asp:TextBox>
        </p>
    <p>
        <asp:Label ID="lblCPPhone" runat="server" AssociatedControlID="txtCPPhone" 
            Text="Contact Person Phone"></asp:Label>
        <asp:TextBox ID="txtCPPhone" runat="server" TabIndex="20" Text=""></asp:TextBox>
    </p>
</div>
    </asp:Panel>

Open in new window

protected void chkMSame_CheckedChanged(object sender, EventArgs e)
    {
          if (chkMSame.Checked == true)
            {
                txtMAddress.Text = txtSAddress.Text;
                txtMCity.Text = txtSCity.Text;
                ddlMState.SelectedValue = ddlSState.SelectedValue;
                txtMZip.Text = txtSZip.Text;
            }
    }

Open in new window

0
Comment
Question by:vcbertini
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 250 total points
ID: 34129800
You have to enable the 'AutoPostback' property of the checkbox to true. Then only server side events get triggered.

Raj
<asp:CheckBox ID="chkMSame" runat="server" CssClass="black12Bold" TabIndex="11"  AutoPostBack="true" 
                Text="Address information is the Same As Above" 
                OnCheckedChanged="chkMSame_CheckedChanged"  />

Open in new window

0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 34129837
by default autopostbacks are disabled on check boxes, radiobuttons, drop downs etc
0
 

Author Closing Comment

by:vcbertini
ID: 34130760
Ah! Thank you. I'm new to ASP.NET and still learning. Thanks for the information. Still grasping this Autopostback stuff and how it works exactly.
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34133721
Thanks for the points, vcbertini,

PostBack
PostBack is the name given to the process of submitting an ASP.NET page to the server for processing . PostBack is done if certain credentials of the page are to be checked against a database (such as verification of username and password). This is something that a client machine is not able to accomplish and thus these details have to be ‘posted back’ to the server
Courtesy:- http://www.dotnetspider.com/forum/158932-What-auto-post-back.aspx

Read these articles for more clearer idea about AutoPostBack
http://www.w3schools.com/aspnet/prop_webcontrol_textbox_autopostback.asp
http://www.dotnetspider.com/resources/189-AutoPostBack-What-How-works.aspx

Regards
Raj
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question