Solved

ascx asp.net c#

Posted on 2010-11-22
13
659 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hidden Field Value 10 60
Entity Framework 3 46
Remove greater than sign 3 45
Split in Javascript 5 31
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 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

15 Experts available now in Live!

Get 1:1 Help Now