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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add Custom Controls

Status
Not open for further replies.

meenakshidhar

Programmer
Oct 19, 2001
77
0
0
MY
Hi Friends,
Can anyone tell me how to add custom controls in asp.net application. I add the reference of that control (.dll) in my asp.net application but getting this error--

Could not load type <<Namespace.Class>> from assembly <name>, Version=1.0.1866.27417, Culture=neutral, PublicKeyToken=null.


Regards,
Meenakshi Dhar
 
I think the DLL has to be in the root of your application.

Then you need to add the Register directive to the aspx. file to declare the control

 
I created one webcontrol using VB..then i m trying to include that control in my ASP.Net application...
what i have done is..
first i add reference of vb dll into my asp application and then in my aspx page i add the following line at the top...

<%@ Register TagPrefix="FIT" Assembly="RTFBox" namespace="RTFCustomControl" %>

where assembly is the class file..
 
I might be on the wrong track but is the assembly RTFBox.dll in the web application root folder
 
yes it is there in the bin folder but not working...
My Namespace=RTFCustomControl
My Class=RTFBox

this is wht i mentioned in the aspx file but i don't know why it's not working...
 
Hi rotsey,
The exact code is--
___________________________________________________________

My Web Control (MControl.vb)

Namespace MCustomControl
Public Class MControl
Inherits System.Web.UI.WebControls.WebControl
Implements IPostBackDataHandler

code.....

End Class
End Namespace
_________________________________________________________

My ASP.Net application(WebForm1.aspx)

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="GTDNet.WebForm1" ValidateRequest="false" %>
<%@ Register TagPrefix="GTD" Assembly="MControl" namespace="MCustomControl" %>
<HTML>
<HEAD>
<Title>Testing </Title>
</HEAD>
<Body>
<Form id="Form1" Runat="server">

<GTD:MControl Runat="server" ID="txtTest"></GTD:MControl>
<asp:Button id="Button1" Text="Button" runat="server"></asp:Button>
</Form>
</Body>
</HTML>
_________________________________________________________

In my asp.net application, i added a reference i.e. MControl.dll in bin directory.

Now the error which i m getting after running webform1.aspx is ---
"Parser Error Message: Could not load type MCustomControl.MControl from assembly MControl, Version=1.0.1871.20543, Culture=neutral, PublicKeyToken=null."

Urgent help needed...
Regards,
Meenakshi Dhar


 
ok..no probs..anywayz thanks a lot...

Regards,
Meenakshi Dhar
 
I am a little confused about your naming conventions. I usually have my namespace the same name as the project and the dll would also be the same name. Not sure if this is right or wrong but it keeps it clear in my head. In my aspx I have
<%@ Register TagPrefix="cc1" Namespace="ControlLibrary1" Assembly="ControlLibrary1" %>

And my all of my controls in a project would the same namespace ControlLibrary1 and each control would have its own class name. So my code in the aspx I would have

Protected MyCtrl As ControlLibrary1.ControlClassName

If your dll is MControl I would try this

<%@ Register TagPrefix="GTD" Assembly="MControl" namespace="MControl" %>

then in my codebehind

Protected MyCtrl As MControl.MControl

then you should see your methods after typing MyCtrl.

Not sure if this will work for you since your dll is your class name and I'll assume your project name is MControl or you changed the compile options to produce a different dll than the project name.
You are right you have to add a reference.
Marty
 
thanks Marty...i think there is some problem in naming conventions...Could you please correct this---

My Namespace= MControl
My Control Class Name=MClass
My Dll= MControl

In my code behind file its showing--
Protected MyCtrl As MControl.MControl.MClass (why ??)

and in my aspx page i m using --
<%@ Register TagPrefix="GTD" Assembly="MControl" namespace="MControl" %>
 
Hi cappmgr,
i think the problem is with vb dll...if i follow the same procedure in C#..then it's working perfectly alright...

In Case of C#--

Namespace=ABC
Project Name=ABC
Class Name= WebCustomControl1

In my code behind file its showing--
Protected WithEvents md1 As ABC.WebCustomControl1

and in my aspx page i m using --
<%@ Register TagPrefix="test" Assembly="ABC" namespace="ABC" %>

i m totally confused now...don't know where is the problem...

Reagrds,
Meenakshi Dhar

 
Meenakshi Dhar,
You should not be confused you have it now. Just use the same naming conventions in your vb app. It's all the same just the systax is different.

Namespace=ABC
Project Name=ABC
Class Name= WebCustomControl1

Now your dll will be ABC.dll this is the reference you add.

You have the correct syntax in the aspx
<%@ Register TagPrefix="test" Assembly="ABC" namespace="ABC" %>

you wrote
Protected WithEvents md1 As ABC.WebCustomControl1
which looks like vb

so md1 will be the id in your aspx

<test:WebCustomControl1
id="md1" runat="server"></test:WebCustomControl1>

then in your codebehind just type md1. and you should see your properties and methods of your class.

if you have it working in C# it's the same as VB. Let us know if this resolves the issue. It seems to be a FAQ, and many will benefit from your post.

Marty
 
Hi cappmgr,
well well finally i got the solution...the procedure for vb.net & C# is same but make sure there isn't a "root namespace" specified for your control in the project properties, this is a "feature" of VB.net.

This was the only problem..

Thanks for your help.

Regards,
Meenakshi Dhar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top