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
Related
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.
I'm using ASP.NET MVC 4 and I'm trying to load a Google Map on my page.
I'm using Subgurim lib and already have the map object, but I don't know how to load it into the page.
Here's what I got so far:
#model Subgurim.Controles.GMap
#{
ViewBag.Title = "Pesquisa Carona";
}
<h2>PesquisaCarona</h2>
<h4>Diga o endereço</h4>
<input type="text" name="txEndereco" />
<input type="submit" />
<cc1:GMap ID="googleMap" runat="server" /> <!-- This doesnt work!!!--!>
I know that normally I would add the map accessing it directly like:
For the serverside:
GMap1.addGMarker(oMarker);
And for the page:
<cc1:GMap ID="GMap1" runat="server" Height="300px" Width="300px" />
But with MVC I can't do that.
Cheers!
I was able to the the basic example to work using .NET 4.5, MVC 5 (razor), GMaps 4.1.0.6, and Visual Studio 2013 by rendering an ascx user control as a partial in the cshtml. Here is what I did to get it to work:
Add the Subgurim.Maps package from NuGet.
Add an ascx control: In my case it was Gmap.ascx placed in the same folder as the cshtml I wanted to use. Your code should end up looking like the following:
In the ascx:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Gmap.ascx.cs" Inherits="YourApp.Views.Gmap" %>
<%# Register Assembly="GMaps" Namespace="Subgurim.Controles" TagPrefix="gmaps" %>
<form id="form1" runat="server">
<gmaps:GMap
ID="GMap1"
runat="server"
Width="500px"
Height="250px"
EnableViewState="False" />
</form>
In the ascx.cs:
namespace YourAPP.Views
{
using System;
using System.Drawing;
using System.Web.Mvc;
public partial class Gmap : ViewUserControl
{
protected void Page_Load(object sender, EventArgs e)
{
GMap1.enableDragging = false;
GMap1.Language = "en";
GMap1.BackColor = Color.White;
GMap1.Key = "YOUR GOOGLE KEY";
GMap1.CommercialKey="YOUR COMMERCIAL KEY";
}
}
}
In the cshtml:
#Html.Partial("Gmap")
** A couple of things to note:
The form tag in the ascx is required it won't work without it.
The control needs to inherit from ViewUserControl instead of UserControl to work with razor.
Make sure you have your keys for the control (Google, Commercial). See the control site for details on those.
If you didn't put the control in the same folder as your cshtml you will need to adjust the path given to the Partial helper.
Thank you to:
The subgurim forums for the last bit about needing the form tags and the basic example.
How to display WebForms .ascx as partial view in MVC 3 for how to load an ascx into a razor view.
If I left anything out please go easy this is my first one.
I hope this helps - Cheers,
Anker
I've got the same problem.
On my project (made with MVC3) I've added a partial view in aspx engine (the rest of my website is with razor). I followed the subgurim tutorial site. Then I added the google api key but I get a gray rectangle even if everything seems ok!
Then I found this post on google: http://it.googlemaps.subgurim.net/Foro/general-discussions-perm5956-5963.aspx
:(
I'm one of the developers of the project and we are working on a new version suitable for MVC (Razor or other view engine of choice). I'll update this response when it's ready for production.
I have an asp.net website with a master-page, can I use the iframe so my .aspx pages will load inside the iframes. (Meaning it wont load the master-page)
Kinda like my iframe will be the contentplaceholder or maybe the contentplaceholder will be inside it?
Any Ideas?
try this
<iframe name="myIframe" id="myIframe" width="400px" height="400px" runat="server"></iframe>
Expose this iframe in the master page's codebehind:
public HtmlControl iframe
{
get
{
return this.myIframe;
}
}
Add the MasterType directive for the content page to strongly typed Master Page.
<%# Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits=_Default" Title="Untitled Page" %>
<%# MasterType VirtualPath="~/MasterPage.master" %>
In code behind
protected void Page_Load(object sender, EventArgs e)
{
this.Master.iframe.Attributes.Add("src", "some.aspx");
}
Another option is to use placeholders.
Html:
<body>
<div id="root">
<asp:PlaceHolder ID="iframeDiv" runat="server"/>
</div>
</body>
C#:
iframeDiv.Controls.Add(new LiteralControl("<iframe src=\"" + whatever.com + "\"></iframe><br />"));
How about:
<asp:HtmlIframe ID="yourIframe" runat="server" />
Is supported since .Net Framework 4.5
If you have Problems using this control, you might take a look here.
You can think of an iframe as an embedded browser window that you can put on an HTML page to show another URL inside it. This URL can be totally distinct from your web site/app.
You can put an iframe in any HTML page, so you could put one inside a contentplaceholder in a webform that has a Masterpage and it will appear with whatever URL you load into it (via Javascript, or C# if you turn your iframe into a server-side control (runat='server') on the final HTML page that your webform produces when requested.
And you can load a URL into your iframe that is a .aspx page.
But - iframes have nothing to do with the ASP.net mechanism. They are HTML elements that can be made to run server-side, but they are essentially 'dumb' and unmanaged/unconnected to the ASP.Net mechanisms - don't confuse a Contentplaceholder with an iframe.
Incidentally, the use of iframes is still contentious - do you really need to use one? Can you afford the negative trade-offs associated with them e.g. lack of navigation history ...?
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