Improve company productivity with a Business Account.Sign Up

x
?
Solved

Request for sample code - C# and ASP.NET

Posted on 2016-08-23
14
Medium Priority
?
84 Views
Last Modified: 2016-08-26
I am requesting someone write a sample project for me that has the following parameters:

2 projects, one named Parent, one named Child.

Parent:
-webforms application
-only one page named Default.aspx
-will reference Child.DLL
-Has no knowledge of Child project location...all it has is the compiled DLL.


Child:
-webforms application
-has only one item, Child.ascx  (web user control)
-has one property, a string called FirstName
-at runtime will generate text inside of a <div> that says, "Hello <First Name>"
-compiles as Child.DLL
-Has no knowledge of Parent.DLL

I need detailed step-by-step instructions of how to deploy Child.DLL and how Parent consumes Child.DLL in order to make use of the web user control.

The reason for my request is that I have been having nothing but trouble getting the above to work.  It seems simple to me, but for some reason I just keep running into problems.  So I am thinking maybe if someone can generate a very simple web page that uses the web control, maybe I will realize what I am doing wrong.  I am sure it is something simple.

Right now I after Referencing the Child.DLL I am not sure what to do our how to expose the web user control inside the DLL.  I tried adding the Child.DLL to the Toolbox via "Choose Items..." but it said it could not load the Type Library.

Parent codebehind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Parent
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}

Open in new window



Parent markup:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Parent.Default" %>

<%@ Register Src="~/Child.dll" Namespace="Child" Assembly="Child" TagName="SayHello" TagPrefix="sh"%>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>    
    <div>
    Parent web form

        <sh:SayHello ></sh:SayHello>
    </div>    
   
</body>
</html>

Open in new window






Child codebehind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

        }

        public string FirstName
        {
            get
            {
                return firstnamediv.InnerHtml;
            }

            set
            {
                firstnamediv.InnerHtml = "Hello " + value;
            }
        }
    }
}

Open in new window


Child markup:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Child.ascx.cs" Inherits="Child.Child" %>
<div id="firstnamediv" runat="server"></div>

Open in new window

0
Comment
Question by:Tom Knowlton
  • 10
  • 3
14 Comments
 
LVL 71

Assisted Solution

by:Éric Moreau
Éric Moreau earned 1000 total points
ID: 41767311
>>I tried adding the Child.DLL to the Toolbox via "Choose Items..."

You need to add a reference not as an item in the Toolbox (which is only for controls and components).

Your best way to do it would be to create a single solution containing the 2 projects.

For the deployment, just copy the child.dll at the same place as the parent.
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 41767372
Let's just pretend, for the moment, that all I have is the Child.DLL.

How do I make use of ChildDLL inside of the Parent solution?
0
 
LVL 71

Expert Comment

by:Éric Moreau
ID: 41767382
from the Project menu, select Add References...
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
LVL 5

Author Comment

by:Tom Knowlton
ID: 41767394
Done.
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 41767403
This is what I get now:

cannot find ascx

Here is the parent markup:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Parent.Default" %>

<%@ Register TagPrefix="uc" Namespace="Child" Assembly="Child" %>

<%--<%@ Register TagPrefix="uc" Namespace="myctrl" Assembly="App_Web_0tcaeix_" %>--%>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>    
    <div>
    Parent web form

        <uc:Child FirstName="Tom" runat="server"/>
    </div>    
   
</body>
</html>

Open in new window


Parent code behind:

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

namespace Parent
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {            
            //Child.Child c = new Child.Child();

            //c.FirstName = "Tom";

            //this.Controls.Add(c);
        }
    }
}

Open in new window

0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 41768975
ping
0
 
LVL 71

Expert Comment

by:Éric Moreau
ID: 41769000
I have tried creating a simple web app on my laptop yesterday and VS froze twice. Today, I don't have much time for this and hope that somebody else could take the ball rolling!
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 41769074
No worries, thank you for communicating, Eric.

Here is my current project as a ZIP file (rename extension from "123" to "zip")
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 41769086
The first attempt to attach the file failed.

Here it is.
Default.aspx.cs
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 41769087
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 41769088
Could not attach the zipped file.
0
 
LVL 19

Accepted Solution

by:
Manoj Patil earned 1000 total points
ID: 41771339
You cannot use an ascx via http. Essentially you are trying to get the ASP.NET compiled and processed output of the user control if you do that.

Is this what you want ?

http://webproject.scottgu.com/CSharp/usercontrols/usercontrols.aspx

User Control Libraries Tutorial
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 41771731
That is a Custom Server Control, right?

Yes, I decided to go that route.  I am no longer pursuing the .ascx.
0
 
LVL 5

Author Closing Comment

by:Tom Knowlton
ID: 41771734
Thanks!

Tom
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Native ability to set a user account password via AD GPO was removed because the passwords can be easily decrypted by any authenticated user in the domain. Microsoft recommends LAPS as a replacement and I have written an article that does something …
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.
Watch the video to know the simple way to remove or recover or reset lost or forgotten passwords of Outlook PST file. With Kernel Outlook Password Recovery tool such operation is very easy to perform. It is a freeware with limitation to use with 500…

585 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