I am busy learning about Umbraco but I don't see anything on the internet that tells me if Umbraco will allow me to create a custom ASP.NET form using C# code connecting to a SQL Server Database.
Would I have any issues with Umbraco if I need to create such a custom form in ASP.NET and bring it into Umbraco?
There are two ways (that I know of, at least) where you can implement custom .Net forms in Umbraco (Version 4.7.x and below).
Template-Based
You can build the form directly in the template markup using standard ASP.Net controls and using a <script runat="server" language="c#"> tag. This is standing inline page coding as you would in Visual Studio, so you give up the luxuries of pre-compilation etc.
<%# Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
<asp:Label ID="myLabel" runat="server" />
</asp:Content>
<script runat="server" language="c#">
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.myLabel.Text = "Hello World";
}
}
</script>
Macro-Based
Build your forms in User Controls in Visual Studio and compile it.
Copy the .ascx to the /usercontrols/ folder.
Copy the .dll to the /bin/ folder.
Navigate to Developer > Macros in Umbraco and create a new Macro
Select your user control from the drop down next to .Net User Control on the Macro Properties tab.
Import you macro into your template. Done!
(Optional) If you user control requires properties to be set, don't forget to add them to properties tab in your macro and map them.
Your template code will look something like the following:
<%# Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
<umbraco:Macro Alias="MyForm" MyProperty="Hi!" runat="server" />
</asp:Content>
Another fast and cheap option is using the Contour Forms package. It costs about 99 euros and provides a WYSIWYG interface to creating forms. It has workflow and the ability to store the values in custom tables.
We really like it and it works for probably 75% - 80% of cases where you need a form.
http://umbraco.com/products/more-add-ons/contour.aspx
You can definitely do this in version 4.7 (and earlier versions), by creating a asp.net custom control, and then adding it into the system - its all pretty easy to do.
In V5 you can't create custom controls since it is now MVC based, and as I am just getting upto speed on v5, can't comment on how hard/different it is yet.
Which version are you using?
Related
I used ScriptManager in .aspx page to Maintain URL history in .Net i.e.
on aspx page i put this script after form tag
> <asp:ScriptManager runat="server" ID="ScriptManager1" EnablePartialRendering="true"
> EnableHistory="true">
> </asp:ScriptManager>
and in my .js file i put this code
Sys.Application.add_navigate(function (sender, e) {
navigate(sender, e);
});
Sys.Application.addHistoryPoint(objOut, null);
Now same thing i want to use in MVC 4 with Razor
I used MicrosoftAjax.js for ScriptManager and .js code is same.
but i am getting issue on callback.
let me explain you with example:
suppose Actual URL is
www.websitename.com/cat/30/
anchor tag link on page is
www.websitename.com/cat/30/?q=10
once callback perform anchor tag link becomes
www.websitename.com/?q=10
I mean after callback "cat/30/" is missing from link.
can anyone tell me what I am doing wrong.
Thanks.
Ashu
ScriptManager is part of ASP.NET Webforms. It is not available in ASP.NET MVC. They are two completely different frameworks.
There is a port of ScriptManager to ASP.NET MVC which is available here. It might provide what you are looking for.
I was coding an aspx page to use the telerik grid. But telerik is not showing in intellisense of VS 2008.
Following are the things done so far:
1. Added the telerik dll in the reference folder.
Code part
<%# Page Language="C#" Inherits="System.Web.Mvc.ViewPage"%>
<%# Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%# Import Namespace="Telerik.Web.Mvc" %>
Index
<% foreach(var v in (List<String>)ViewData["names"])
{
Response.Write(v);
%>
<br />
<%
}
%>
<% Html. %>
Thanks
The Visual Studio Intellisense in views is far from perfect. Personally what I do is to add the assembly (<assemblies> tag) and the namespace (<namespaces> tag) in web.config, so that it is available in all views. This way I no longer need to add any Import section in each view. After doing this you probably might need to reopen the view for the changes to take effect. Even restart Visual Studio. If it works at runtime and you don't get Intellisense at compile-time, well, I wish they improve it in future versions.
i'm trying to make my site master page (views/shared/site.master) strongly typed.
eg. Inherits="TestProject.Mvc.Views.Shared.Site"
I can't seem to get this work. Once i make the site.master page strongly, typed, Visual Studio seems to 'loose' what <%= Html.XXX %> is. Also, the page throws an error when i try to display the default index route.
The SiteMasterViewData class exists in the views/shared/ folder and has been included at the top of the master page via..
<%# Import Namespace="TestProject.Mvc.Views.Shared"%>
Can this be done? is there a better way to do this?
Damn - found my own answer.
All masterpages in the ASP.NET MVC v1. need to inherit from:
<%# Master
Language="C#"
Inherits="System.Web.Mvc.ViewMasterPage" %>
so if u want to strongly type it, you can do this.
<%# Master
Language="C#"
Inherits="System.Web.Mvc.ViewMasterPage<SiteMasterViewData>" %>
HTH's other peeps :)
I have tried to use ASP.NET MVC for a while, then I face a problem that I don't want to include all of my js and css in master page. But how can I register it in head of master page from my specific view?
The default master page template includes a Content PlaceHolder for the head. If it doesn't you can easily add one:
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server" />
</head>
Your views can then put anything they want in the head:
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script src="Scripts/myScripts.js" type="text/javascript"></script>
<link href="Styles/myStyles.css" rel="stylesheet" type="text/css" />
</asp:Content>
It doesn't look like there's a simple option 'built-in' to the ASP.NET MVC framework just yet. If you are using a user control (.ascx), which you may be if you are creating self-contained controls which also want to manage their own JavaScript requirements, then you can't even use the placeholders to help you out.
In the end I created a helper class and in it there are a couple of methods:
private static SortedList<int, string> GetRegisteredScriptIncludes()
{
var registeredScriptIncludes = System.Web.HttpContext.Current.Items["RegisteredScriptIncludes"] as SortedList<int, string>;
if (registeredScriptIncludes == null)
{
registeredScriptIncludes = new SortedList<int, string>();
System.Web.HttpContext.Current.Items["RegisteredScriptIncludes"] = registeredScriptIncludes;
}
return registeredScriptIncludes;
}
public static void RegisterScriptInclude(this HtmlHelper htmlhelper, string script)
{
var registeredScriptIncludes = GetRegisteredScriptIncludes();
if (!registeredScriptIncludes.ContainsValue(script))
{
registeredScriptIncludes.Add(registeredScriptIncludes.Count, script);
}
}
public static string RenderScripts(this HtmlHelper htmlhelper)
{
var registeredScriptIncludes = GetRegisteredScriptIncludes();
var scripts = new StringBuilder();
foreach (string script in registeredScriptIncludes.Values)
{
scripts.AppendLine("<script src='" + script + "' type='text/javascript'></script>");
}
return scripts.ToString();
}
That's a basic form of it anyway to try and show the way it works. It could be enhanced in many ways, but at the moment it just filters out duplicate script insert requests for you. Whenever you want to add a new script in the ascx (or aspx for that matter) you can do it this way:
<%
Html.RegisterScriptInclude(Url.Content("~/Scripts/MapLayers/MapLayer.js"));
Html.RegisterScriptInclude(Url.Content("~/Scripts/MapLayers/Vehicles.js"));
%>
Then you need to remember to output them once you're done. This is achieved by making the following call at the place in your page where you want to output the script tags:
<%=Html.RenderScripts() %>
Seems to work so far for me. I did half expect to have rendering issues depending at what point RenderScripts was called, especially if not all of the RegisterScriptIncludes had been called yet, but so far it seems to do the job. If you render the scripts last then you should have no problems.
#Jason: WARNING, you shouldn't be using static variables like this... In a web context static variables are shared across all users and all page requests. I am amazed that you haven't run into trouble with your code. The principle is fine but the code is wrong and will give you trouble. In this case you should be using System.Web.HttpContext.Current.Items. See http://www.hanselman.com/blog/ATaleOfTwoTechniquesTheThreadStaticAttributeAndSystemWebHttpContextCurrentItems.aspx for more.
Here is a solution similar to the one Jason gave, but takes vdh_ant's comments into consideration:
http://frugalcoder.us/post/2009/06/29/Handling-Scripts-in-ASPNet-MVC.aspx
technically you should be putting all your js at the bottom of the page for the best performance.
I think the only way you could do this though would be to include the javascript in the VIewData and have the ViewData displayed on the masterpage (not a great solution).
MVC Futures now has built in helpers for this...
1.<head>
2. <title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
3. <%= Html.Css("BlueTheme/site.css") %>
4. <%= Html.Script("jquery-1.3.2.js") %>
5.</head>
More information here: http://blog.osbornm.com/archive/2009/10/12/mvc-script-css-helpers.aspx
Mathew,
I took a look at your blog on Html.Css and Html.Script helpers. I don't mean to be critical but I do not see any mention in the blog about how the Css and Script helpers would address the problem discussed here. The problem here is one of needing to "registered" script references at any point during the rendering process, and possibly multiple times (in the case of an template or partial view that is used several times and registers its own scripts), and then outputting the aggregate results, sans duplicates, in a single location.
If your solution addresses this, please correct me with some clarification.
--Regards,
Ken
I wrote just such a manager for MVC, and wrote about it on my blog:
"JavascriptHelper–Managing JS files for ASP.NET MVC"
UPDATE: I added bundling:
"JavascriptHelper:Managing JS files for ASP.NET MVC (With Bundling)"
Yeah, its a bit on this side of pointless, but I was wondering... I've got all these codebehind files cluttering my MVC app. The only reason why I need these files, as far as I can tell, is to tell ASP.NET that my page extends from ViewPage rather than Page.
I've tried a couple different Page directives changes, but nothing I've found will allow me to identify the base class for the page AND let me delete the codebehind files.
Is there a way to do it?
UPDATE: I'm trying to inherit from a strongly-typed ViewPage! Seems like its possible to inherit from a regular ViewPage...
Delete the codebehind and use a page directive like this:
<%# Page Title="Title" Inherits="System.Web.Mvc.ViewPage" Language="C#" MasterPageFile="~/Views/Layouts/Site.Master" %>
Or, if you want to get rid of the codebehind but still want to use strongly typed view, then read this link: http://devlicio.us/blogs/tim_barcz/archive/2008/08/13/strongly-typed-viewdata-without-a-codebehind.aspx
Here is a cut and paste of what this would look like:
<%# Page Inherits="System.Web.Mvc.ViewPage`1[[ABCCompany.MVC.Web.Models.LoginData, ABCCompany.MVC.Web]]" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" %>
Assuming you don't have any code in your codebehind, why don't you point them all to one codebehind file?
Straight out of the box you should be able to delete the .designer.cs and nothing will break. The other code behind can be useful, for instance if you'd like to strongly type your viewdata.