.NET 3.5 sp 1 beta is sexy
/Half way down - see the script combining feature.
I really like how this will optimise the number of network traffic, but I think it can make debugging scripts slightly harder if the lines change between postbacks.
jliu
Code zealot in a connected world
Half way down - see the script combining feature.
I really like how this will optimise the number of network traffic, but I think it can make debugging scripts slightly harder if the lines change between postbacks.
jliu
I've been experimenting with the anonymous types we have in C# 3.0, here's my latest creation:
var actions = new[]
{
new { Name = ActionSave, Type = KnownActionType.Save },
new { Name = ActionCopy, Type = KnownActionType.Copy },
new { Name = ActionNew, Type = KnownActionType.New },
// snipped another 10 actions...
};
foreach (var action in actions)
{
Actions.Add(new Action(action.Name, action.Type));
}
C# happily compiled this for me, to my surprise. And it works just as I expected it to.
Even intellisense picked it up properly. See, strongly typed goodness.
The most amazing part I wasn't expecting is the C# compiler knowing that all the array items are the same anonymous type. So it must have worked that bit out somewhere.
---
Prior to the amazing var variable, you would to do this with nasty looking nested object[] setup. Like so:
(warning, untested code)
object actions = new object[]
{
new object[] { ActionSave, KnownActionType.Save },
new object[] { ActionCopy, KnownActionType.Copy },
new object[] { ActionNew, KnownActionType.New },
// snipped another 10 actions...
};
foreach (object action in actions)
{
// reall awful looking line next
Actions.Add(new Action((string)action[0], (KnownActionType)action[1]));
}
There are heaps of things wrong with this old way:
Yes. I think I'm going to do nested anonymous types next.
jliu
I want to add a star to the end of a label for mandatory fields in the DOM.
.mandatoryIndicator { font-color: red; }
var star = document.createElement("span");
star.setAttribute("class","mandatoryIndicator");
star.innerHTML = " *";
label.appendChild( star );
The above code doesn't work in IE, the star is added, but it remains the default text colour.
I did a bit of hunting around and found out the problem is actually with setAttribute. It doesn't work with half a dozen properties on the element.
The fix is actually quite easy, use this:
var star = document.createElement("span");
star.className = "mandatoryIndicator";
star.innerHTML = " *";
label.appendChild( star );
I find the .NET anonymous type a bit weak in terms of a few more features:
I guess anonymous types are purely for quick throw-away data constructs. I might just as well write a class directly with all the stuff I wanted.
The job of a framework library is to provide a basic package of necessary services and components.
In ASP.NET, being a web application, the UI portion of the framework has to provide not only server side code, but also CSS, JavaScript and image files.
ASP.NET 2.0 made it easy with the WebResourceAttribute. And I was hunting for a bug today:
Page.ClientScript.RegisterClientScriptResource(GetType(),
"My.Framework.Web.UI.Pages.Collapse.js");
We have this bit of code on the masterpage in the framework, as soon as we use this in applications it stops working.
We get a 404, "invalid webresource request".
The issue actually was quite easy to fix once we what the Type argument was for. It's for ASP.NET to work out which assembly to look for the resource.
Page.ClientScript.RegisterClientScriptResource(typeof(ATypeInTheFrameworkAssembly), "My.Framework.Web.UI.Pages.Collapse.js");
Which fixed the problem.
I look at how a small team can build amazing things with the latest tools we have in Office 365 & SharePoint. I'm a coder, developer, Office SharePoint MVP. I dream, then I rant.
Founder @ Flow Studio App
A poweruser tool to help every maker write better Microsoft Flows and manage them.
MVP Alumni Office Apps and Services: SharePoint
MVP Alumni Business Applications: Flow
This work by John Liu is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Permissions beyond the scope of this license may be available at /about-me/.