• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 89
  • Last Modified:

Request for sample code - C# and ASP.NET

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
Tom Knowlton
Asked:
Tom Knowlton
  • 10
  • 3
2 Solutions
 
Éric MoreauSenior .Net ConsultantCommented:
>>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
 
Tom KnowltonWeb developerAuthor Commented:
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
 
Éric MoreauSenior .Net ConsultantCommented:
from the Project menu, select Add References...
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 
Tom KnowltonWeb developerAuthor Commented:
Done.
0
 
Tom KnowltonWeb developerAuthor Commented:
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
 
Tom KnowltonWeb developerAuthor Commented:
ping
0
 
Éric MoreauSenior .Net ConsultantCommented:
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
 
Tom KnowltonWeb developerAuthor Commented:
No worries, thank you for communicating, Eric.

Here is my current project as a ZIP file (rename extension from "123" to "zip")
0
 
Tom KnowltonWeb developerAuthor Commented:
The first attempt to attach the file failed.

Here it is.
Default.aspx.cs
0
 
Tom KnowltonWeb developerAuthor Commented:
0
 
Tom KnowltonWeb developerAuthor Commented:
Could not attach the zipped file.
0
 
Manoj PatilSr. Software EngineerCommented:
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
 
Tom KnowltonWeb developerAuthor Commented:
That is a Custom Server Control, right?

Yes, I decided to go that route.  I am no longer pursuing the .ascx.
0
 
Tom KnowltonWeb developerAuthor Commented:
Thanks!

Tom
0
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

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 10
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now