Solved

How to include ascx into dll or reference multiple user controls in web.config?

Posted on 2008-10-22
4
1,399 Views
Last Modified: 2010-08-05
Hello Expert!

Here is my point. I've a Projet Class Library who have 21 user controls with code behind file
ex: usercontrol1.ascx, usercontrol1.cs....

How can i include the ascx content into the dll file?

What i need is a easy way to use my usercontrol in different pages without register in the page.

When I try to add "controls" into the "<pages><controls>" in the web.config i got a error. I guest it's because i can't specify the "src" wheres the ascx are located.

I know i can manually add controls 1 by 1 on the page controls element in web.config.

But is there any way to add a "Global Reference"?

Thanks!
Projet namespace and assambly: mynamespace.customctrl
 
usercontrol.ascx
-----------------
<%@ Control Language="C#" AutoEventWireup="true" Inherits="mynamespace.customctrl.ctrlone,mynamespace.customctrl " %>
<asp:Button ID="Button1" runat="server" Text="Button" />
 
usercontrol.cs
------------------
namespace mynamespace.customctrl
{
    public class ctrlone : System.Web.UI.UserControl
    {
        protected Button Button1;
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Button1.Text = "Custom text";            
        }        
    }
}
 
mypage.aspx
-------------------
<customctrl:ctrlone ID="ctrl1" runat="server" />
 
 
web.config
-----------------
<pages>
  <controls>
     <add tagPrefix="customctrl" namespace="mynamespace.customctrl" assembly="mynamespace.customctrl"/>
</controls>
</pages>

Open in new window

0
Comment
Question by:jabcoco
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 6

Expert Comment

by:WanaBRich
ID: 22785842
You have to regesiter the user controls in the page that's it's being used in that is the way the asp.net framework works. Sorry
0
 
LVL 10

Author Comment

by:jabcoco
ID: 22787735
OK, or maybe registring all controls individualy in pages/controls using this patern in web.config
<pages><controls>
<add tagPrefix="customctrl" tagName="ctrlone" src="~/MyUserControls/usercontrol.ascx" />
</controls></pages>

right?
Thanks
0
 
LVL 6

Accepted Solution

by:
WanaBRich earned 500 total points
ID: 22790702
Yes that should work. http://msdn.microsoft.com/en-us/library/ms164640.aspx might be of some help

0
 
LVL 10

Author Closing Comment

by:jabcoco
ID: 31509046
Thanks :)
0

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

695 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