Checkbox control in Asp.Net

I'm trying to capture a person's current and permanent address.

If the current and permanent address are the same, it means there is no need to enter the same information twice. I'm using a checkbox to indicate that the addresses are the same.

If the checkbox gets checked, I would like to put the current address into the permanent address controls. How do I do that?

Answers


You can achieve this functionality in numerous ways with both Server Side code (C#) or with Client Side code (JavaScript or jQuery). Without seeing what you currently have built, it is hard to tell you what the best fit is... Below is a sample of how to populate a text box with data from another with the Check Box is checked...

SERVER SIDE EXAMPLE

C#
protected void MyCheckBox_CheckedChanged(object sender, EventArgs e)
{
    this.MySecondTextBox.Text = this.MyFirstTextBox.Text;
}
ASP
<asp:TextBox ID="MyFirstTextBox" runat="server"></asp:TextBox>
<asp:CheckBox ID="MyCheckBox" runat="server" 
    oncheckedchanged="MyCheckBox_CheckedChanged" />
<asp:TextBox ID="MySecondTextBox" runat="server"></asp:TextBox>

CLIENT SIDE EXAMPLE

C#
protected void Page_Load(object sender, EventArgs e)
{
    this.MyCheckBox.Attributes.Add("onClick", "CopyText()");
}  
ASP
<asp:TextBox ID="MyFirstTextBox" runat="server"></asp:TextBox>
<asp:CheckBox ID="MyCheckBox" runat="server" />
<asp:TextBox ID="MySecondTextBox" runat="server"></asp:TextBox>
<script type="text/javascript" language="javascript">
    function CopyText() {
        var txt2 = document.getElementById("<%= this.MySecondTextBox.ClientID %>");
        txt2.value = document.getElementById("<%= this.MyFirstTextBox.ClientID %>").value;
    }
</script>

Need Your Help

.htaccess mod_rewrite to create clean URLs

php .htaccess mod-rewrite

I have a data driven site that passes information to determine what the next page should show using the $_GET parameter.