Solved

ascx asp.net c#

Posted on 2010-11-22
13
654 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
  • 9
13 Comments
 
LVL 5

Expert Comment

by: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: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: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
 
LVL 5

Expert Comment

by: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: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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 5

Expert Comment

by: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: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: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:
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now