Using a User Control from Another Project - c#

I have built a user control in a project that I want to re-use in a separate project. I had seen similar attempts successfully accomplished by adding a reference to the original project and then registering the control via:
<%# Register Assembly="AssemblyName" Namespace="AssemblyName.Namespace" TagPrefix="xxx" %>
I did something similar, compiling the original project and referencing it in the subsequent one . The control has an asp:Repeater control within it. I then registered my control as above and placed the control on my page like so (the control has a string property named prop):
<xxx:ControlName ID="ControlId" runat="server" prop="21" />
However when I launch the control in the subsequent project, I get a null reference exception and the application chokes. Am I doing this the wrong way? Is it mandatory that I have an .ascx file in the subsequent project?
Any and all help is appreciated.
Thanks,
pbr

Just as a follow up to this:
I did some further research and learned that the mark-up language (materials on the .ascx page) do not get compiled into the assembly. Therefore you must have the .ascx file within the project that calls it if there is any markup associated with the control.
In the properties dialogue I set up a post-build event that copies the .ascx file over to the subsequent project Controls file. I reference it as I would any normal User Control and everything works fine.
Hope this helps someone out there with a similar issue,
pbr

Related

ASP.NET Webforms Deployment & Markup Changes

In ASP.NET Web Forms, I know when the C# changes the primary DLL also needs to be deployed. I also know when the markup (.aspx, .master) changes where new controls are added, the primary DLL needs to be deployed.
What about when the markup (.aspx, .master) changes and no controls are added? Can the .aspx or .master page be changed without deploying the associated DLL? I see 2 scenarios that may have different answers:
Simple markup changes (e.g. HTML, CSS. JS)
Dynamic changes in the markup (e.g. add <%=Page.ResolveUrl("~/test.aspx") %>)
**Note:
Ideally I'd deploy the whole app on any change, but I'm dealing with a fragile legacy app.
.aspx or .master pages be changed without deploying the associated DLL provided changed contents/controls don't change the interaction with the server-side code. For example in Home.aspx you add a paragraph <p>Sometext</p> deploy just Home.aspx, application would keep working.
On the other hand, obviously, if any control name is changed/event is added, you need to deploy associated DLL (after necessary updates).
I hope this helps!

Content of webpage doesn't display in Module in DotnetNuke

I am new in DotnetNuke. So, first of all I don't know all terminology. My problem is content of Webform.aspx doesn't display in Module.
Let me describe the steps so it can be easy to track the missing steps if any.
1- Created a project of DotnetNuke 7 C# Compiled Module. Path:
F:\website\dnndev.me\desktopmodules\DNNModule2
2- Added a WebForm1.aspx and add a line "Hello World"
3- Build project, DNNModule2_00.00.01_Install.zip is generated in
F:\websites\dnndev.me\DesktopModules\DNNModule2\DNNModule2\install
4- Added extension in http://www.dnndev.me/Admin/Extensions. It added
successfully in Modules.
5- Created New Page and added DNNModule2 by drag and drop. But it
doesn't display content "Hello World" of WebForm1.aspx.
Do I need to set any property while I am adding Module in New WebPage?
Also suggest if my flow is wrong. I will be happy to improve.
Thanks
For a DNN module to work properly you need to work with an .ascx user control. Typically these will inherit from the PortalModuleBase class. There are a few options, but that is the most common.
.aspx pages themselves can exist in DNN, however, they are ONLY available if you access them directly, and not through the module process.
Your user control, when setup should be part of the .dnn manifest and referenced with a <controlkey/> value. (As in no control key defined, to be the default view of your module.)
If you are not using a template, this one is a great example.

How can I embed or navigate to a page contained in another namespace

I have two projects in one solution. One contains a page (which is basically a complex control) and another project which is an empty XAML application. What I'm wondering is how to either embed the page into the empty XAML project's main page or at least be able to navigate to it.
Any ideas?
How about Frame.Navigate(typeof(MyControl.MainPage))?

Codebehind file doesn't recognize aspx-controls

I was given a webproject written with aspx/c#. When I loaded it into Visual Studio 2010, I got many error telling me that some controls in the code-behind files do not exist in the current context.
I checked for the common pitfalls, like wrong code-behind file name, missing runat-attribute, restart VS, reload project, yet nothing resolves the error.
What else can I do to check where the problem is?
Try to change the code-behinde to CodeFile="where code locate", then it probably will work.
inherit class for the markup file and code behind file should match ,and also make sure if these controls are not third party and may need referencing their dlls or something .If these controls are user controls(ascx) controls , make sure they are using the correct tagname in the register line at the top .
Cudos to #03Usr the following link brought the answer:
ASP.NET controls cannot be referenced in code-behind in Visual Studio 2008
Deleting all designer files and converting the project als web application brought the designer files back, effectively making the controls referenceable again.
This is a really annoying hack but if you delete the control from the aspx page and then save the page, then paste the control back onto the page and save again the code behind then seems to recognize the control. I keep running into this problem whenever I change an attribute like the ID.
In my case, the aspx file was inside a folder named XYZ, and the class name was ABC. So ASP named the C# file's class name as XYZ_ABC
After renaming the file to ABC, the error was fixed
Hope it helps!

How to deploy a single user control which has changes to the cs file (ascx.cs)

I have a user control (UserControl1.ascx) and I made changes to Its cs file.
That UserControl1.ascx is being used by two or more aspx files using LoadControl.
I don't want to deploy the whole web project dll as this is a fix for a critical issue in a part of the web app and doesn't affect the whole web app.
Updating changes to the single web form code behind is easily done. However not sure about the single user control deployment. Any help is appreciated.
it's a bit of a hack but you could move the code from the .ascx.cs file to the .ascx file and remove the inherits attribute. Asp.net first checks the referenced class in the inherit attribute. So I think this should allow you to update the web application without updating the .dll files. I didn't test this however, but I think it could be a viable option.
If you just deploy the updated user control (ascx) form and the relevant DLL, the only discernible delay will be the load time of the first hit after deployment, which you can do yourself with a browser refresh.

Categories

Resources