Link to home
Start Free TrialLog in
Avatar of Webboy2008
Webboy2008

asked on

ascx asp.net c#

I have two ascx file. called primary address, mailing address.
in the maling address ascx, i have a check box called same as primary address.
If it is checked, the primary address will be copied and shown in the mailing address.
how can I do it in two ascx file?
500 points if you have completed working codes.

thanks
Avatar of Tom Knowlton
Tom Knowlton
Flag of United States of America image

Here is the primary address control markup:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="primaddress.ascx.cs" Inherits="WebApplication1.primaddress" %>

Prim Address:
<asp:TextBox ID="PrimAddy" runat="server"></asp:TextBox>
<br />
<br />
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" 
    oncheckedchanged="CheckBox1_CheckedChanged" Text="Same for Secondary" />

Open in new window

Here is the primary address control code-behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public delegate void SameAddressChecked(object sender, EventArgs e);

    public partial class primaddress : System.Web.UI.UserControl
    {
        public event SameAddressChecked SameAddressEvent;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        {
            if(CheckBox1.Checked)
            {
                if(SameAddressEvent != null)
                {
                    SameAddressEvent(this.PrimAddy.Text, null);
                }
            }
        }
    }
}

Open in new window

Here is the secondary address control markup:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="secaddress.ascx.cs" Inherits="WebApplication1.secaddress" %>

Sec Address:  <asp:TextBox ID="SecAddy" runat="server"></asp:TextBox>

Open in new window

Here is the secondary address control code-behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class secaddress : System.Web.UI.UserControl
    {
        public string SetSecAddress
        {
            set { SecAddy.Text = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}

Open in new window

Here is the Default.aspx markup:


<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

<%@ Register src="primaddress.ascx" tagname="primaddress" tagprefix="uc1" %>
<%@ Register src="secaddress.ascx" tagname="secaddress" tagprefix="uc2" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="ContentPlaceholder2">
   
    <uc1:primaddress ID="primaddress1" runat="server" />
    <br />
    <br />
    <uc2:secaddress ID="secaddress1" runat="server" />
   
</asp:Content>

Open in new window

Here is the Default.aspx code-behind:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            primaddress1.SameAddressEvent += new SameAddressChecked(primaddress1_SameAddressEvent);
        }

        void primaddress1_SameAddressEvent(object sender, EventArgs e)
        {
            secaddress1.SetSecAddress = sender as string;
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}

Open in new window

Here is the master page markup (not really needed, except my new projects  default to using one):
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="WebApplication1.SiteMaster" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head runat="server">
    <title></title>
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
    <asp:ContentPlaceHolder ID="HeadContent" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form runat="server">
    <asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
    </asp:ContentPlaceHolder>
    </form>
</body>
</html>

Open in new window

Master page code-behind (again, of no real consequence):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Tom Knowlton
Tom Knowlton
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Webboy2008
Webboy2008

ASKER

hello...the checkbox should be in mailing address ascx. not primary. please have one completed codes in a file / message attached.

thanks
Avatar of Kumaraswamy R
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.