User Control in a content page

I am trying to register a user control in a content page.  The problem is the user control is in a directory "above" the content page.  For example.  the content page is in the directory \folder1\folder2\page.aspx.  The user control is in directory \folder1\usercontrol.ascx.

This gives the error:
"System.Web.HttpException: The 'href' property had a malformed URL: Cannot use a leading .. to exit above the top directory.."

I register the control:
<@ Register TagName="rightMenu" TagPrefix="rm" Src="~/_IFrames/AboutUs/rightMenu.ascx">

Code to load the control:
<rm:rightMenu ID="rightMenu1" runat="server" />

4/30/2009 2:46:25 PM 13714 articles. 0 followers. Follow

7 Replies

Similar Articles

[PageSpeed] 24

Try following steps -

  1. Remove all registration code lines in ASPX Source.
  2. Remove the control on the page.
  3. Switch to Design view.
  4. Drag and drop the .ASCX file from Solution Explorer to the .ASPX page.
  5. This drag and drop automatically creates the control on the page and registers itself in ASP source.


Please mark as answer if this post solves your problem.


Harshad Kale.
Software Engineer
Pune, Maharashtra,
4/30/2009 5:07:15 PM
That still gave the same error.  it is interesting though, because the control is displayed in design view, but when i try to access the page i get the error.

If i put the user control in the same directory or a "child" directory then it will work.  Does anyone know if there is some security reason why I can't access the user control in a "parent" directory?
4/30/2009 5:14:07 PM

If your folder structure is ..



I would think Registering the User control is done by

<%@ Register Src=""/folder1/usercontrol.ascx"" TagName="SomeUserControl" TagPrefix="ExampleUC" %> 

Basically without the "~"

I think the Tilde("~") is giving you access to Root project folder, You already know where your User Control is so You don't need to try and go to root and back up again.

4/30/2009 5:32:07 PM

The Double Quote on the Src attribute is by mistake

4/30/2009 5:34:49 PM
That didn't fix it.  Same error.

Just to see if the master page was causing any problems, i created a test page that did not use a master page.  then in design view i dragged the user control onto the page (displayed great), but when i opened the page in a browser, i got the same error.  

I just tried doing the same thing on a second website i maintain and it worked fine. any ideas out there? something in the webconfig?
4/30/2009 5:53:43 PM

it seems the error didn't come from your operation to put the UC on the page. Instead, it came from your UC itself. Not sure what were in your UC.

Suggest you generate a simple UC with only one lable, then put it in your page for testing.

"Object reference not set to an instance of an object"
4/30/2009 6:41:44 PM
You were correct.  thanks.  Silly error on my part.
5/4/2009 2:25:47 PM

Similar Artilces:

Problem to use TreeView Control in a 'content page' This Error Occur "Only Content controls are allowed directly in a content page that contains Content controls."
hi I am trying to use the TreeView Control inside the content page (Page that has a master page is a content page). On compiling the project I got the following ASP.Net runtime error: "Only Content controls are allowed directly in a content page that contains Content controls."B@b@R J Issue resolved. I was putting script tag in the content page that is not allowed. when remove the script from content page problem is resolved.B@b@R J...

convertion from page to content page or from user control to content page
Hi, I have converted an 1.1 application to 2.0.  Now what I am looking for some enhancement.  I added a master page and now I want to add other pages as content pages. but those pages which I am converting into content have some user control. Now either I can convert those user control to content pages ( which i want to look for if it is possible),  Or I am thinking i shouldn't convert those user control to content pages cause they might be just good. So looking for some of those people opinion who have worked through this so can I get opinion here please.thanks&nb...

Need to access a Label Control on the Master Page from a user control attached to a content page
Hello all, I have a master page (say  site.master)  with a status Label in it. I have a content page ( say content.aspx)  that has a user control (say usercontrol.ascx). One of the Button Click Events in the usercontrol.ascx needs to pass on some text onto the status label on the masterpage(LabelStatusMsg) and display it. I have been able to do this directly off a content page (content.aspx) by using the following code (VB)  on the master page <%@ MasterType virtualpath="~/site.master" %> and Dim mpLabel As Label = CType(Master.FindControl("LabelStatusMsg"),...

How to do post back in a dynamically created user control [provided that update panel is in the master page of the page where user control is added] {B/C of FileUpload Control}
I have a register my scriptmanager and place the update panel around contenttempalte for my pages int the master page. Now in one of my pages i am adding some user controls dynamically. In two of my user user controls I have FileUpload control which will not work under partial post back. So I want's full postback for them How could I do that {Provided that i am on the user control,which is inside the page ,and page have the contenttemplat...

Content controls have to be top-level controls in a content page or a nested master page that references a master page.
Why in the world am I getting this error? The solutions I have seen either don't apply or don't work.  Here is my master page code:<%@ Master Language="C#" AutoEventWireup="false" CodeFile="TechLMSMasters/MainSide.master.cs" Inherits="MainSide" %> <%@ Register TagPrefix="usercontrol" TagName="Search" Src="~/library/uc/Search.ascx" %> <%@ Register TagPrefix="usercontrol" TagName="UserName" Src="~/library/uc/UserNameDisplay.ascx" %><!DOCTYPE html PUBLI...

How to access page control (editor control) from user control?
Hi, I want to do something, but I don't know if it's even possible. I'm trying to make a simple application to edit my website. I have a page called editPage.aspx which contains an editor control. (cuteEditor from cutesoft) I also have a Treeview that dynamically populates my website structure. I placed this treeview in a custom control (populateTreeView.ascx) and placed it on the editPage.aspx page. When you click on a html file in the treeview (inside the custom control) I check if the file exists. If it does exists I send it to a class which retrieves the editable region within this ...

Error : Content controls have to be top-level controls in a content page or a nested master page that references a master page.
when I make a directory on my root, and in that directory I put a masterpage and a web form ... I get always an error : Content controls have to be top-level controls in a content page or a nested master page that references a master page.   Does somebody know what the problem is ? Is it possible you can't set a masterpage in a directory ... ?Kind Regards,Joeri Pansaerts.From Bruges, Belgium :) i've founded ... I had to nest my masterpage ...Kind Regards,Joeri Pansaerts.From Bruges, Belgium :) Hi Joeri Pansaerts, I am receiving the same error as the one posted her...

ERROR Content controls have to be top-level controls in a content page or a nested master page that references a master page.
This all used to work until about 5 minutes ago. Did I change something? For some reason I am now getting this error: Content controls have to be top-level controls in a content page or a nested master page that references a master page. What I have:  I have a masterpage inside of a directory. That directory is a first level directory with its own web.config file....The whole thing is protected by the web.config file above it (in the main public directory). That main public directory has a masterpage as well. I am not currently linking the two masterpages together becuase...

Only Content controls are allowed directly in a content page that contains Content controls.
Hi Friends, I created one Master Page.In this I created one Default.aspx .Here I added Content Place Holder,here I am doign the program which is realted to Regisration  Form. I wrote the javascript in source code of content place holder.But its not supporting the java script and its showing the errors in the script(it is in bold in the following source code)I wrote the code like following<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title=&qu...

Only Content controls are allowed directly in a content page that contains Content controls.
 Hi all,I am using gridview to display data add i am using checkbox so that when a person  chech  the box it display information regarding that.At local server its run fine but when i upload this on website it gives following exception.Offending URL: System.WebMessage: Exception of type 'System.Web.HttpUnhandledException' was thrown.Stack trace: at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPo...

Only Content controls are allowed directly in a content page that contains Content controls.
Hello I got this error message whenever I place this script below on my inline code: this.RegisterClientScriptBlock("keyClientBlock", "<script>alert ('Javascript block of code executed')</script>");             Please advice.Thanks  Try this: this.ClientScript.RegisterClientScriptBlock(this.GetType(), "key", "script");HTH   My Blog Thanks for the reply but doesn't work for me :(I tried placing the script on string variable before...

page/user control controls
hello. if my page contains a user control. what happens if i try to save stuff to the viewstate using both the page AND the user control? does one override the other? are they kep seperate? thanks. 1. How to do you plan to "save" the View State 2. Where do you want to save it? 3. What type of data are you saving, the ViewState collection (a StateBag), the information converted from it and returned through Control.SaveViewState(), or the data converted by the Page's SavePageStateToPersistenceMedium?--- Peter BlumCreator of Peter's Data Entry Suite (formerly Profes...

Only Content controls are allowed directly in a content page that contains Content controls. #2
Hi, Trying to add:  Response.Write("<script language='javascript'>'PO_export.asp?C=" + sql + "'); </script>") Getting error (in subject).  Anyone help? Thanks, Mark Why don't you try to add the javascript in the head section of the page.Bind GridView to Dynamically created DataTable | Bind DataTable to DropDownListMy Blog Hi Mark, Based on your description, the issue is error message appears when you add JavaScript code to the content page. After reviewing your code, I find nothing wrong with it. I...

Add user control from user control to web page
Hi there, I have a user control, that is inside another user control on a web page. From this user contfol, I need to add something to a place holder on the parent web page. I am having troubles referencing the placeholder correclty. I can get it fine as build time, but on runtime it kicks up the "Object reference not set to an instance of an object" error. Any ideas would be greatly appreciated. -------------------------------------------------------------- protected Civil_and_Corporate.candcadmin._default _default; ------------------------- Control objControl...

Using controls from pages, master pages, and user controls
How would I structure my site in this scenario: I'd like to use a dropdownlist all over my site, sometimes in a regular page, sometimes in a master page, and sometimes in a user control.  I wish to bind its events programmatically, so normally I would just put that in the codebehind.  However, I notice a lot of code duplication because I have to declare the control in everywhere, in my base page (which all my pages inherit from), in my base master page (which all my master pages inherit from) and in my base user control (which all my user controls inherit from).How should I be...

Web resources about - User Control in a content page -

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

WA bushfires: Firefighters work through the night to control several blazes
Firefighters in Western Australia are working through the night to control and contain several blazes.

MAZEL TOV, HILLARY: Clinton Wins Gun Control Award From Major Anti-Bill of Rights Group
... restrictions on the freedoms protected by the Constitution is not a sign of character, but a clear indication of blind adherence to a gun control ...

Democrats New Plan For Gun Control – A Secret Government Terrorist Watch List
They call it the "Denying Firearms and Explosives to Dangerous Terrorists Act of 2015"

The Legend of Zelda: Twilight Princess Wii U will likely support Wiimote and Nunchuk controls
Well this is interesting. Fans have been speculating as to the control schemes that will be supported in The Legend of Zelda: Twilight Princess ...

USB Volume Control
... computer speakers, they often have a volume knob you can mount somewhere on your desk so you aren’t dependent on the onboard volume control. ...

ICYMI: Even the AP couldn’t validate any of Hillary’s gun control nonsense
... – not 200 as she claimed . Asked to explain the discrepancy, Clinton’s campaign pointed to 2013 statistics from the Centers for Disease Control ...

5 Questions: Punjab’s rightful control over Chandigarh, says Prem Singh Chandumajra
Shiromani Akali Dal (Badal) MP Prem Singh Chandumajra on why he raised the issue of Punjab’s claim over Chandigarh in LS.

Over-The-Counter Birth Control Empowers Women And Pharmacists In Oregon And California
Over-the-counter birth control is coming to Oregon and California. There’s an enactment of new laws on the horizon that will allow pharmacists ...

In this Dark Fairy Tale, a Sheltered Young Girl Seizes Control of Her Future
“In a family headed by a tyrannical father, the younger daughter will regain her freedom on her birthday.” It’s a simple synopsis, but Blood ...

Resources last updated: 11/28/2015 2:11:45 AM