I'm attempting to start using DynamicData functionality in a previously existing website. Basically I'm following this tutorial. When I got to the part about creating the Field Templates I decided I could probably create a new site with the Dynamic Data stuff built in, and then just copy the folder over.
Unfortunately when I do that and try to compile I get the error "Could not load type..." for just about every .ascx file in the DynamicData directory. I named the "new" project the same as the pre-existing site so that the namespace would be the same... but I can't think of what else I could be missing.
Everything looks ok, except that the *.ascx.Designer.cs files are showing inside the Solution Explorer. I tried deleting one and then copying that file back into just the directory but it didn't work. I'm assuming I need to do something special with those so that Visual studio handles them properly and can compile?
Here is one of the .aspx files:
<%# Control Language="C#" CodeBehind="FilterUserControl.ascx.cs" Inherits="EService.FilterUserControl" %>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
EnableViewState="true" ontextchanged="new">
<asp:ListItem Text="All" Value="" />
</asp:DropDownList>
Here is the matching .cs file:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Web.DynamicData;
namespace EService
{
public partial class FilterUserControl : System.Web.DynamicData.FilterUserControlBase
{
public event EventHandler SelectedIndexChanged
{
add
{
DropDownList1.SelectedIndexChanged += value;
}
remove
{
DropDownList1.SelectedIndexChanged -= value;
}
}
public override string SelectedValue
{
get
{
return DropDownList1.SelectedValue;
}
}
protected void Page_Init(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
PopulateListControl(DropDownList1);
// Set the initial value if there is one
if (!String.IsNullOrEmpty(InitialValue))
DropDownList1.SelectedValue = InitialValue;
}
}
}
}
And here is the .ascx.designer.cs file:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.1433
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace EService
{
public partial class FilterUserControl
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;
}
}
EDIT: If I create the file in the website, then copy the contents from the temporary site I created it seems to compile just fine. Really have no idea what the issue is here... I tried manually modifying files to match the results of copying and they still wouldn't work unless I actually created them in the site. It's just bizarre...
The problem was due to the temporary site creating the <%# Control > definitions with the CodeBehind property instead of the CodeFile property. For some reason pages in the actual website will only compile when CodeFile is declared...
DD will work with Either Website or Web Application. however when copying in from an other project the types need to be the same otherwise it's lot of editing to convert swee my article here Getting Dynamic Data Futures filters working in a File Based Website.
Related
I want to add Bundles into an existing ASP.NET MVC 4 (.NET 4.5) website that uses:
Umbraco 6.1.5
Microsoft ASP.NET Web Optimization Framework 1.1.3 (https://www.nuget.org/packages/microsoft.aspnet.web.optimization/)
I attempted to follow these directions: https://gist.github.com/jkarsrud/5143239, and the CSS loaded fine before I started down the bundles path.
On page load it inserts the style reference:
<link href="/bundles/marketingcss" rel="stylesheet">
But a 404 error happens:
> GET http://localhost:20459/bundles/marketingcss 404 (Not Found)
Here's what I've in code:
Web.Config
<add key="umbracoReservedPaths" value="~/umbraco,~/install/,~/bundles" />
Global.asax
<%# Application Codebehind="Global.asax.cs" Inherits="MapCom.Global" Language="C#" %>
Global.asax.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Optimization;
using System.Web.Security;
using System.Web.SessionState;
using Umbraco.Web;
namespace MapCom
{
public class Global : UmbracoApplication
{
protected void Application_Start(object sender, EventArgs e)
{
base.OnApplicationStarted(sender, e);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
}
_Layout.cshtml
#Styles.Render("~/bundles/marketingcss");
BundleConfig.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Optimization;
namespace MapCom
{
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
BundleTable.EnableOptimizations = true;
///
///Marketing Site CSS Bundle
///
bundles.Add(new StyleBundle("~/bundles/marketingcss")
.Include("~/plugins/bootstrap/css/bootstrap.min.css")
.Include("~/css/font-awesome.min.css")
.Include("~/plugins/parallax-slider/css/parallax-slider.css")
.Include("~/css/combinedStyles.min.css")
.Include("~/plugins/ladda-buttons/css/ladda.min.css")
.Include("~/plugins/ladda-buttons/css/custom-lada-btn.css"));
}
}
}
Any ideas?
After much digging into Umbraco, I noticed that the project I'm working on is utilizing a class:
public class ApplicationEventHandler : IApplicationEventHandler
Which is explained in more detail here: http://our.umbraco.org/documentation/Reference/Events/application-startup
But the gist is:
In order to bind to certain events in the Umbraco application you need to make these registrations during application startup. Based on the Umbraco version you are using there are various ways to hook in to the application starting. The higher the version you are using the more robust this becomes.
So Umbraco's overriding some of the ASP.NET start-up methods.
I solved my issue by adding a reference to System.Web.Optimization in ApplicationEventHandler.cs and moved my bundle registration to this method in that class:
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
The ONLY thing that worked for me here was adding the path to the bundle to the following setting in web.config
My bundle Code
BundleTable.Bundles.Add(new ScriptBundle("~/opt/jscripts").Include(
"~/Scripts/twitterFetcher.js"
));
BundleTable.EnableOptimizations = true;
Umbraco default setting
<add key="umbracoReservedPaths" value="~/umbraco,~/install/" />
New setting
<add key="umbracoReservedPaths" value="~/umbraco,~/install/,~/opt/" />
try the following suggestions:
1.Do not use keyword bundles for your css virtual path so just change it to something else, and use the keyword bundles for your scripts only.
like this:
bundles.Add(new StyleBundle("~/Content/marketingcss")
(Remember you need to make sure that if you have a file called marketingcss under content folder you should change the virtual path to something else, so the virtual path shouldn't duplicate the physical path)
2.in your _Layout.cshtml use the following line instead of yours:
#Styles.Render(BundleTable.Bundles.ResolveBundleUrl("~/Content/marketingcss"))
3.if the above suggestions didn't work then try this one in your _Layout.cshtml instead:
<link href="#System.Web.Optimization.BundleTable.
Bundles.ResolveBundleUrl("~/Content/marketingcss")"
rel="stylesheet"
type="text/css" />
updated
4.just saw one of our friend's comment about not to putting .min files in your bundle, which is correct so you must not include .min files in your budleConfig class, and just use the normal files like bootstarp.css instead of bootstrap.min.css and do the same for all other files, of course make sure you have the normal files first so not just change the names.
I hope it helps to fix your code
I try to create a custom control which inherits from GridView ( using tut http://msdn.microsoft.com/en-us/library/yhzc935f(v=vs.100).aspx ). After each build Visual Studio keeps replacing my reference to my custom namespace with its own in Default.aspx.designer.cs
protected global::System.Web.UI.WebControls.WebParts.GridViewCustom GridView1;
each time I did put
protected GridViewCustom.GridViewCustom GridView1;
Why ?
In assembly.cs I have added
using System.Web.UI;
...
[assembly: TagPrefix("GridViewCustom", "GridViewCustom")]
In default.aspx I have:
<asp:GridViewCustom ID="GridView1" runat="server">
</asp:GridViewCustom>
This is my source code for the control (source file is in App_Code):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace GridViewCustom
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:GridViewCustom runat=server></{0}:GridViewCustom>")]
public class GridViewCustom : System.Web.UI.WebControls.GridView
{
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["Text"] = value;
}
}
protected override void RenderContents(HtmlTextWriter output)
{
output.Write(Text);
}
}
}
I'm having the same problem. One option is suggested by the autogenerated designer file -- remove the declaration from the .designer.cs file and explicitly declare it in your codebehind file.
Otherwise, you might try looking into the solution outlined in this question: Visual Studio 2010 keeps changing my winforms control.
Update:
Having registered my controls globally in a web.config file, I just experimented with changing the tagPrefix declaration to something unique, as opposed to an existing prefix shared by other custom controls, and suddenly everything is fine. The strange thing is that I no longer see the declaration in the designer file, but it still works.
Still confusing.
I have an .aspx file that has 3 drop down lists:
ddlMake
ddlModel
ddlColour
i have a Page_Load function but i cant acces them in the Page_Load function...
using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace NorthwindCascading
{
public partial class _IndexBasic : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CarService service = new CarService();
List<string> Makes = service.GetCarMakes();
ddlMake.DataSource = Makes;
ddlMake.DataBind();
ddlMake.Items.Insert(0, " -- Select Make -- ");
}
}
}
}
I have added the code-behind file manually so i guess i am missing something... it just says that the ddlMake element is not defined in current context...any suggestions?
Rather than figure out what went wrong. I suggest you just simply delete the file and re-do what you have done again. Will save your time....
Make sure your CodeFile/CodeBehind attribute in the page directive is pointing to the correct file. If so, make sure the Inherits attribute in the page directive is naming the correct class name.
If you added the code behind manually, then the _IndexBasic.designer.cs probably doesn't contain the protected members, which would be why you cannot see them here. Or, your aspx is not referencing this as your codebehind.
Right-click on your .aspx page and hit Convert to Web Application - that will create and populate the designer file.
I have defined the following control which serves as a wrapper for another control (simplified code):
using System.ComponentModel;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Company.Dept.Project.Controls.ControlName
{
[
AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal),
AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal),
DefaultProperty("Text"),
ValidationProperty("Text"),
ToolboxData("<{0}:ControlName runat=\"server\"> </{0}:ControlName>")
]
public class ControlName : WebControl, INamingContainer
{
private TextBox _myTextBox;
public string Text
{
get
{
EnsureChildControls();
return _myTextBox.Text;
}
}
protected override void CreateChildControls()
{
_myTextBox = new TextBox { ID = "MyTextBox" };
Controls.Add(_myTextBox);
}
}
}
Which is used in a user control:
<%# Register Assembly="Company.Dept.Project.Controls" Namespace="Company.Dept.Project.Controls TagPrefix="MyControls" %>
<MyControls:ControlName ID="ControlName1" runat="server" />
When run locally from the ASP.NET Development Server, DIT Server and SIT Server, the control renders and operates as expected. However, on the UAT Server, I receive the following error:
System.Web.HttpException: 'Company.Dept.Project.Controls.MyControls' is not allowed here because it does not extend class 'System.Web.UI.UserControl'
Can anyone provide any insight as to why it is failing in one environment, but not the others? Is this something related to configuration? The user control is hosted within a "SmartPart" style user control loader which is being used on a WSS 3.0 site in the DIT/SIT/UAT environments.
Thanks!
It appears that this error can occur when a referenced assembly is missing.
The issue was resolved after rebuilding the installation packages and redeploying.
Is it possible to write a System.Web.UI.Page and stored in an assembly?
And how can I make iis call that page?
So I will go deeply...
I'm writing a class like that:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Runtime.InteropServices;
using System.Reflection;
using WRCSDK;
using System.IO;
public partial class _Test : System.Web.UI.Page
{
public _Test()
{
this.AppRelativeVirtualPath = "~/WRC/test.aspx";
}
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("You are very lucky!!!");
}
}
That are stored into an assembly.
So Now How can I register that assemply and obtain that http://localhost/test.aspx invoke that class?
Thanks.
Bye.
You'll want to use an HttpHandler or HttpModule to do this.
Registering the assembly is just like registering any assembly -- just define that class in a code file and have the compiled DLL in your bin directory.
Then, as an example, you can create a IHttpHandlerFactory:
public class MyHandlerFactory : IHttpHandlerFactory
{
public IHttpHandler GetHandler(HttpContext context, ........)
{
// This is saying, "if they requested this URL, use this Page class to render it"
if (context.Request.AppRelativeCurrentExecutionFilePath.ToUpper() == "~/WRC/TEST.ASPX")
{
return new MyProject.Code._Test();
}
else
{
//other urls can do other things
}
}
.....
}
Your web.config will include something like this in the httpHandlers section
<add verb="POST,GET,HEAD" path="WRC/*" type="MyProject.Code.MyHandlerFactory, MyProject"/>
Not sure what you're after here. If you set up a deployment project, there's a setting to have it merge all the dll files into a single assembly. Is that what you want? Either way, if you want to reuse the same code behind class for several aspx pages, it is the page declarative (1st line of code in the aspx) that you must change.
Few options
1. You can refer to this assembly as part of visual studio references
2. Use relfection to load the assembly and class from your test ASAPX page.