Solved

ascx asp.net c#

Posted on 2010-11-22
13
681 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

728 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