Solved

Request for sample code - C# and ASP.NET

Posted on 2016-08-23
14
51 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:knowlton
  • 10
  • 3
14 Comments
 
LVL 69

Assisted Solution

by:Éric Moreau
Éric Moreau earned 250 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: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 69

Expert Comment

by:Éric Moreau
ID: 41767382
from the Project menu, select Add References...
0
 
LVL 5

Author Comment

by:knowlton
ID: 41767394
Done.
0
 
LVL 5

Author Comment

by: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:knowlton
ID: 41768975
ping
0
 
LVL 69

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Author Comment

by: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:knowlton
ID: 41769086
The first attempt to attach the file failed.

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

Author Comment

by:knowlton
ID: 41769087
0
 
LVL 5

Author Comment

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

Accepted Solution

by:
Manoj Patil earned 250 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: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:knowlton
ID: 41771734
Thanks!

Tom
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
c# regex: extract & replace text between braces 6 30
install app on other machine 13 16
Visual Studio editor? 1 18
XML & .net 5 21
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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