asp.net MVC - conditional compilation directly in aspx (site.master)? - asp.net

I seem to be having an issue with the conditional compilation tags directly en my site.master..
basically i have the following but it reports "Cannot resolve symbol DEBUG" in the compiler alhough i can run in DEBUG and RELEASE ... but the final output always prints whats in DEBUG weather i am in RELEASE or DEBUG...
And as mentioned the compiler doesn't complain but it has little red lines under debug with the error msg.. What am i doing wrong? Can anyone help?
<%# Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
<% #if DEBUG %>
<link href="../../Content/CSS/test.css" rel="stylesheet" type="text/css" />
<script src="../../Content/Scripts/jquery-1.3.2.js" type="text/javascript">
</script>
<% #else %>
<link href="../../Content/CSS/StyleSheetFinal.css" rel="stylesheet" type="text/css" />
<script src="../../Content/Scripts/JavascriptFinal.js" type="text/javascript"></script>
<% #endif %>

I've never used the conditional compilation tags in aspx pages, but I have one idea on what might be wrong. When you say "run in DEBUG" or "run in RELEASE", exactly what do you mean? How are you setting it to debug or release mode? If you're just setting Visual Studio to do a debug/release build, that doesn't apply to how the aspx pages are compiled. Whether aspx pages are compiled in debug/release mode depends only on settings in the page header or settings in the web.config.

Check out http://haacked.com/archive/2007/09/16/conditional-compilation-constants-and-asp.net.aspx.

Related

Syntax errors creating an ASP.NET page using MonoDevelop

I'm using MonoDevelop on Ubuntu to create ASP.NET pages. My code is producing syntax errors.
<%# Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head runat="server">
<title>index</title>
<script runat="server"></script>
</head>
<body>
<form id="form1" runat="server">
<p>Hello Word!</p>
</form>
</body>
</html>
1:/home/ublinuxyu/program/c#/index.aspx(0,0): Error CS1525: Unexpected symbol `<' (CS1525) (index)
2:/home/ublinuxyu/program/c#/index.aspx(4,4): Error CS1646: Keyword, identifier, or string expected after verbatim specifier: # (CS1646) (index)
What have I done wrong here?
It looks like you set the build action of the aspx file to "Compile" instead of "Content".
You can fix it using the context menu on the file in the solution pad, or by using the property pad when that file is selected.

Cannot find '/Scripts/IntelliFactory.WebSharper.dll.js' in very basic WebSharper application

I'm developing a very simple WebSharper application and am having difficulties when running it.
My F#/WebSharper library contains Main.fs with the following:
namespace Sandbox35.FsLib
open IntelliFactory.WebSharper
open IntelliFactory.WebSharper.Html
type HelloWorldControl () =
inherit Web.Control()
[<JavaScript>]
override this.Body =
Div [ P [ Text "Hello World" ] ] :> Html.IPagelet
Which I am loading into Default.aspx, containing the following:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Sandbox35.Lib._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<WebSharper:ScriptManager runat="server" />
<title>Sandbox</title>
</head>
<body>
<form id="form1" runat="server">
<SandboxLib:HelloWorldControl runat="server"/>
</form>
</body>
</html>
I'm adding project references and where relevant and entries in the application's web.config file for my server control and handlers for WebSharper as described in the samples on their site.
It all appears to build fine but when I run the application I find that a number of Javascript files can't be found by my browser:
Sandbox.Lib.dll.js
IntelliFactory.WebSharper.dll.js
IntelliFactory.WebSharper.Html.dll.js
They all return with a 404 error.
I'm using VS2010 & .Net 3.5.
Just wondering what else I should check?
The files are usually generated on disk in the Scripts folder under the root of your web project. Are they present? If not, are IntelliFactory.WebSharper.Web targets included in the web project MSBuild file?
<Import Project="$(WEBSHARPER_HOME)\IntelliFactory.WebSharper.Web.targets" />

Trouble With Static UICulture Setting and Implicit Localization

I’m playing with implicit localization on my Win7 box via VS2010 and something doesn’t quite seem right. I have a trivial page where I set the resourceKey of my GO Button to “bnGO”:
<%# Page Language="VB" culture="auto" meta:resourcekey="PageResource1" uiculture="es" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test Implicit Localization</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="bnGO" runat="server" meta:resourcekey="bnGO" />
</form>
</body>
</html>
Then I have both testForm.aspx.resx and testForm.es.aspx.resx files that set the value of bnGO.Text appropriately:
When I run the application, the GO Button displays the "Go Forth!" text defined in the default testForm.aspx.resx even though testForm.aspx has uiculture set to “es” (which I think is Spanish).
What am I doing wrong?
The name of the file should be:
testForm.aspx.es.resx
Not
testForm.es.aspx.resx

Ext.NET DateField - formatting reversing itself

We have a weird situation where an Ext.NET datefield is 'switching' formats if we input values in a certain style.
Specifically, if I input '01/12/09', when I blur the field, it will appear as '12/01/2009'. If I then focus the field and remove the '20' so the format reads '12/01/09' when I blur the field, it will 'switch' and show '01/12/09'.
What's odd is that we only see this behaviour on our production environment. I've done all the obvious things like checking the locale/region settings on the production box but haven't yet found anything which circumvents the behaviour.
Does anyone have any ideas on places to check next? This is based on Ext.js 3.3.1.
Many thanks,
Doug
Here's a simple test I used in an attempt to recreate the problem, although was unable.
<%# Page Language="C#" UICulture="en-GB" %>
<%# Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ext.NET Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:DateField ID="DateField1" runat="server" />
</form>
</body>
</html>
Which version of Ext.NET are you using 1.0, 1.1 or 1.2?
Can you modify the sample above to demonstrate the issue.

Could not load type 'ASP.xxx' when referencing a precompiled master page

I'm attempting to precompile a few master pages (not update-able) to share them across multiple applications. The project I'm precompiling is a Web Site. The project that references precompiled assemblies is a Web Application. However, I'm getting a Could not load type 'ASP.xxx_master' every time i try to reference the master page from the client.
<%# Master Language="C#" Inherits="ASP.sitebase_master" %>
My precompiled master page looks like this.
<%# Master Language="C#" ClientIDMode="Static" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="AspNetHead" runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=7" /><![endif]-->
<asp:ContentPlaceHolder ID="MetaContent" runat="server" />
<title>Web Portal</title>
<link href="/media/css/style.css" rel="stylesheet" type="text/css" />
<link href="/media/js/plugins/colorbox/colorbox.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="StyleContent" runat="server" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript" language="javascript"></script>
<script src="/media/js/plugins/colorbox/jquery.colorbox-min.js" type="text/javascript" language="javascript"></script>
<script src="/media/js/plugins/filestyle/jquery.filestyle.min.js" type="text/javascript" language="javascript"></script>
<script src="/media/js/portal.master.js" type="text/javascript" language="javascript"></script>
<script language="javascript" type="text/javascript">
PORTAL.debug.init();
PORTAL.init();
</script>
<asp:ContentPlaceHolder ID="ScriptContent" runat="server" />
</head>
<body>
<div id="hld">
<div class="wrapper">
<form id="AspNetForm" runat="server">
<asp:ContentPlaceHolder ID="BodyContent" runat="server" />
</form>
<asp:ContentPlaceHolder ID="FooterContent" runat="server" />
</div>
</div>
</body>
I'm stumped. No idea why the type isn't resolved. Anybody got suggestions? Both projects (precompiled web site and client web application) are built for ASP.NET 4.0.
EDIT: Here is the list of dependencies of the precompiled assembly. No 3rd party references.
mscorlib,
System,
System.Web
UDPATE 1
Well, the quick fix to this issue is to specify the full path to the master page.
<%# Master Language="C#" Inherits="ASP.sitebase_master, App_Web_sitebase.master.cdcab7d2" %>
After doing that, I'm receiving the following error:
An error occurred while try to load the string resources (FindResource failed with error -2147023083).
After doing some research, this appears to be related to the way HTML markup is parsed within the master page. Not entirely sure yet. I haven't dug much deeper into it. Overall, I can't believe this is the recommended way to share controls as it is absolutely, mindbogglingly idiotic.
UPDATE 2
I couldn't make anything of value out of this. It appears to be hating "script" tags in the head section, but I don't know why. The Master Page works great with a single script include. As soon as i start adding more I keep getting that error. After wasting a full day on this I ended up submitting a bug report to Microsoft. If anyone wants to bump it, please do.
UPDATE 3
I spent a few more days debugging this after no response from MS. Here is my findings. I initially thought that the code generated by CodeDOM provider is looking for a .NET resource that somehow did not get embedded in the assembly when it was published. I was wrong. After some investigation it appears that what's happening is after the Master Page reaches a certain size, a chunk of it is stored in the Resource Table in PE Data Directories section of the assembly. In fact, after looking at the generated assembly in PE resource viewer, i was able to confirm this by finding all my script includes in the Resource Table. Now, here is the actual problem. What's happening is that the CodeDOM provider generates a call to Win32 FindResource to pull that resource from the Resource Table. However, FindResource doesn't work on assemblies in memory, only on disk. So it fails with the above exception. I'm getting close, but still no workaround.
I finally have a workaround. It's not pretty, but it resolves the issue. Apparently using LoadControl to pre-load precompiled MasterPages loads all of the resources that FindResource cannot find otherwise. So, here is all i did to make this work.
In my client application I created a dummy master page (i.e. Dummy.Master) which references my precompiled master page like so:
<%# Master Language="C#" Inherits="ASP.sitebase_master, App_Web_sitebase.master.cdcab7d2" %>
Now, any .aspx page which references Dummy.Master needs to preload the precompiled MasterPage type like so:
protected override void OnPreInit(EventArgs e)
{
ASP.sitebase_master mp = (ASP.sitebase_master)Page.LoadControl(typeof(ASP.sitebase_master), null);
base.OnPreInit(e);
}
I don't know why this works, but it does. This code must run before the MasterPage is resolved, so PreInit worked great. After glancing at the .NET code for a few seconds in Reflector, it appears that LoadControl actually does some assembly compiling voodoo when it attempts to load a certain control type. So perhaps something in there loads that PE resource data section. The best place to put it would be in the base class I suppose which all pages could inherit from. Also, each loaded control (master page in this case) ought to be cached. Here is a good article explaining just that.
Hopefully this helps someone as much as it helped me. It was a pretty big show stopper for me.

Resources