Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating an assembly custom control with a namespace in vb.net

Status
Not open for further replies.

glyns

Programmer
Dec 15, 2008
125
GB
'm trying to create a compiled user control I can use
I've not got any useful code in at the moment it should just show "hello world"

This is hello.ascx page's code
Code:
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="hello.ascx.vb" Inherits="GControlNS.hello" ClassName="hello"%>
Hello world
this is the .vb code
Code:
Namespace GControlNS
  public Class hello
    Inherits System.Web.UI.UserControl
  End Class
End NameSpace
Which all compiles nicely but when I try to use it in my default.aspx page all I get is a blank page being loaded
Code:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Default.aspx.vb" Inherits="WebApplication1._Default" %>
<%@Register Assembly="GControl" Namespace="GControl.GControlNS" TagPrefix="GControl1" %>

<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head runat="server">
</head>
<body>
<GControl1:hello runat="server" />
</body>
</html>
here's default.aspx.vb
Code:
Imports System.Windows.Forms
Imports GControl
Partial Public Class _Default
    Inherits System.Web.UI.Page
  
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
End Class
Can anyone tell me what stupid mistake I'm making this time or point me to some useful ultra-basic examples of how to do this that'd be lovely
Thanks
 
I'm not sure what you are trying to do, or what a compiled user control is. Maybe what you are after is a custom control.
 
It's just a custom control that I want to compile into a DLL as opposed to putting into the project as a .ascx file. Which I've managed to do :)

We use a few at work and I've replicated the way they're incorporated into the code (or so I thought) but while the user control project compiles, I can't get access to it accessible in the webpage
 
Underneath, sorry, cut-n-paste joy
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="hello.ascx.vb" Inherits="GControlNS.hello" ClassName="hello"%>
Hello World
 
Here's a working example:
Code:
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="hello.ascx.vb" Inherits="GControlNS.hello" %>
Hello World!
Code:
Namespace GControlNS

    Partial Class hello
        Inherits System.Web.UI.UserControl

    End Class

End Namespace
Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default36.aspx.vb" Inherits="Default36" %>

<%@ Register Src="hello.ascx" TagName="hello" TagPrefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]

<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <uc1:hello ID="Hello1" runat="server" />
    
    </div>
    </form>
</body>
</html>


Mark,

[URL unfurl="true"]http://lessthandot.com[/url] - Experts, Information, Ideas & Knowledge
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://aspnetlibrary.com[/url] - An online resource for professional ASP.NET developers
 
I developed the exciting control using "<%@Register Src" and got that working (so I knew I wasn't totally spannering it up :p), now I want to be able to compile the control into a DLL and use it that way using "<%@Register Assembly" the way we access the 3rd party controls we use like this...

Code:
<%@ Register Assembly="ComponentArt.Web.UI" Namespace="ComponentArt.Web.UI" TagPrefix="ComponentArt" %>

I've compiled the control into a DLL, used "<%@Register Assembly" to reference it, it doesn't error any more, but still nothing appears on the screen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top