In Sitefinity - the page controls section I created a new tool and linked it up to the user control. But when I try and add that control to the page I am getting an error?
Is there a step I am missing?
UserControl
Control Language="C#" AutoEventWireup="true" CodeBehind="TransparencyControl.ascx.cs" Inherits="SitefinityWebApp.transparency.TransparencyControl" %>
<%# Register TagPrefix="ucTransparency" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<asp:Xml ID="XmlForm" runat="server"></asp:Xml>
PageControl
PageControl tool linked to ascx page
You need to set the path to the user control (ascx) not in the Controller CLR Type field, but in Control CLR Type or Virtual Path field.
So, just cut it from the former field and paste it in the latter field and you should be fine.
Related
I created this TransparencyControl and would like to be able to add it as a widget. I created this new MyWidget1 but I am not sure where or how to add the User Control? Should it be added to the cshtml page?
TransparencyControl.ascx
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="TransparencyControl.ascx.cs" Inherits="SitefinityWebApp.transparency.TransparencyControl" %>
<%# Register TagPrefix="ucTransparency" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<asp:Xml ID="XmlForm" runat="server"></asp:Xml>
default.cshtml
#model SitefinityWebApp.Mvc.Models.MyWidget1Model
<h1>
#Html.Raw(Model.Message)
</h1>
<p>
<uc:ucTransparency runat="server" ID="ucTransparency" />
</p>
Like #Veselin said, you cannot mix MVC and user controls. You can either register your user control as a widget or use MVC to create the widget.
Webforms:
Have a look at the webforms documentation to see how you can register your user control.
MVC
If you are using MVC(which is recommended), Sitefinity has some sample widgets you can have a look at.
Note that after you implement new widgets, you must register them in the Sitefinity CMS toolbox. You do this by decorating the widget controller class with the ControllerToolboxItem attribute. Sitefinity has documentation on this which can be found here
The problem that i'm having is that i made a master page like i always do. Then i add a views folder and add a web form using master page. But the design from the master page isn't showing on newly made web form.
<%# Page Title="Home - " Language="C#" MasterPageFile="~/App_Themes/Theme/shop.Master" AutoEventWireup="true" CodeBehind="home.aspx.cs" Inherits="Shop.Views.home" %>
You need to check "set masterpage" when you are adding a new webform in visual studio.
I have two pages I want to exclude them from the sitemaster so I can add a check for the session in the sitemaster. I want to exclude them because I want that the 401.aspx page and another page can be accessed by anyone. But the rest should be checked for and authenticated.
Is this possible, and what is the best solution to do this?
Just don't add a MasterPageFile="~/Master.master" statement to your pages (or reference another MasterPage here)
Default:
<%# Page Language="C#" MasterPageFile="~/Master.master" [...] %>
"Special" pages:
<%# Page Language="C#" MasterPageFile="~/AnotherMasterPage.master" [...] %>
Without master:
<%# Page Language="C#" [...] %>
If i understood your question your problem is how to handle errors and redirect to specific files when that happens. This may help http://www.asp.net/hosting/tutorials/displaying-a-custom-error-page-cs and http://msdn.microsoft.com/en-us/library/aa479319.aspx
But if your problem is how to remove master pages from a specific file , you can simply remove it's refrence from your aspx file. remove the MasterPageFile="/Master/default.master"
from your <%# Page Language="C#" ...%>
Hope this helps.
I'm starting with MVC 2 in Visual Studio 2010. The thing is I'm working with a MasterPage where I'm rendering an action which returns a UserControl:
Everything works well, I mean the user control has a lot of other labels and it's rendering other properties... So the problem has nothing to do with anything apart the img tag and the src attribute:
Site.master:
<div class="Test">
<% Html.RenderAction("HeaderDetails", "User"); %>
</div>
HeaderDetails.ascx:
<img src="<%= Model.ImageUrl %>" />
For my surprise I cannot use the Model inside that attribute in a usercontrol, I have the same for a Page.aspx that is working.
The same happens with ViewData["ImageUrl"], I just don't have even intellicense in that attribute. It's like: I cannot do that.
Does anyone know why is that?, or how should I do it?
I kind of got lost towards the end of your question, but in regards to the strongly typed Model in the user control, you'll need your page, masterpage and user control to all inherit with the same type arguments
page:
<%# Page Language="C#" MasterPageFile="Your.Master" Inherits="System.Web.Mvc.ViewPage<YourModelType>" %>
master:
<%# Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage<YourModelType>" %>
control:
<%# Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<YourModelType>" %>
The type arg of the control and master can be base types of YourModelType, but obviously will need to have the ImageUrl property
Well, I have solved it by creating a Custom HtmlHelper using Extension Methods going through this link.
The only matter is that I couldn't use the namespace MyMVCApp.Helpers, I had to use the System.Web.MVC one, so I'm not sure that would be the best way to do it.
If you have some input on that I will appreciate it.
So, I was missing the Import to MyMVCApp.Helpers inside the user control :D
I've just begun experimenting with nested masters in MVC2. I'm not quite sure why I am getting this error.
Parser Error Message: Could not load type 'MySite.Views.Shared.Master'.
I used the add item wizard, created Master.master, and selected it's master to be Site.Master. In one of my views I changed the MasterPageFile from Site.Master to Master.master. I haven't changed any contents. What have I gotten wrong?
It sounds like you've added a Master Page and not a MVC Master Page. You need to make sure that both of your master pages inherit from System.Web.Mvc.ViewMasterPage.
So your master page directives should look like this:
<%# Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
AND
<%# Master MasterPageFile="~/Views/Shared/Site.Master" Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
HTHs,
Charles