Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ascx asp.net c#

Posted on 2010-11-22
13
Medium Priority
?
692 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:Webboy2008
[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
  • 9
13 Comments
 
LVL 5

Expert Comment

by:Tom Knowlton
ID: 34191065
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

0
 
LVL 5

Expert Comment

by:Tom Knowlton
ID: 34191074
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

0
 
LVL 5

Expert Comment

by:Tom Knowlton
ID: 34191083
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

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 5

Expert Comment

by:Tom Knowlton
ID: 34191097
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

0
 
LVL 5

Expert Comment

by:Tom Knowlton
ID: 34191101
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

0
 
LVL 5

Expert Comment

by:Tom Knowlton
ID: 34191115
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

0
 
LVL 5

Expert Comment

by:Tom Knowlton
ID: 34191121
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

0
 
LVL 5

Expert Comment

by:Tom Knowlton
ID: 34191126
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

0
 
LVL 5

Accepted Solution

by:
Tom Knowlton earned 2000 total points
ID: 34191150
1)  Enter an address in the TextBox for the primary address control.
2)  Click the checkbox
3)  An event is raised and consumed by the parent form (Default.aspx)
4)  Public property exposed by secondary address control is used to populate the secondary address text box based upon what is in the primary address text box.

If you want additional fields ... I think you can do that work on your own based upon this basic example.
0
 

Author Comment

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

thanks
0
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 34387754
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.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

609 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