May 2011 - Digital Tool Factory blog May 2011 - Digital Tool Factory blog

The Digital Tool Factory Blog

How to do a cool flash notification message in asp.net mvc 3 in 6 easy steps

I pieced all of this together from various sources online, so the code is a bit rough, but here it is:

1.  Create a partial razor view, call it _NotifyBar.cshtml, it contains this:

@if (Request.Cookies[“NotifyBar”]!=null)
{

var c = new HttpCookie(“NotifyBar”);
c.Expires = DateTime.Now.AddDays( -1 );
Response.Cookies.Add( c );

}

2.  Put this in the header of your _Layout.cshtml file
//here is the jbar stuff

<script type=”text/javascript”>//
$(document).ready(function () {
$(“#message”).fadeIn(2000);
$(“#message”).delay(5000).fadeOut(1000);
$(“#message a.close-notify”).click(function () {
$(“#message”).fadeOut(“slow”);
return false;
});
});
</script>

3.  Right after the body of your _Layout.cshtml page there is this code

@Html.Partial(“_NotifyBar”)

4. Create a file called ExtensionMethods.cs, add in this code

public static ActionResult SetStatusMessage(this ActionResult ar, string str)
{
var c = new HttpCookie(“NotifyBar”);
//c.Expires = DateTime.Now.AddDays(-1);
c.Value = str;
HttpContext.Current.Response.Cookies.Add(c);
return ar;
}

5. Put this in your stylesheet

#message {
font-family:Arial,Helvetica,sans-serif;
position:fixed;
top:0px;
left:0px;
width:100%;
z-index:105;
text-align:center;
font-weight:bold;
font-size:100%;
color:white;
padding:10px 0px 10px 0px;
background-color:#8E1609;
}

#message span {
text-align: center;
width: 95%;
float:left;
}

.close-notify {
white-space: nowrap;
float:right;
margin-right:10px;
color:#fff;
text-decoration:none;
border:2px #fff solid;
padding-left:3px;
padding-right:3px
}

.close-notify a {
color: #fff;
}

6. Then in your controller, just return add “SetStatusMessage” on your RedirectToAction, for example

return RedirectToAction(“Index”).SetStatusMessage(“You have successfully edited the ” + project.ProjectName + ” project.”);

That’s it!  You can now have a fade-out notification message on any page you like.  The use of the cookies is a bit cumbersome, but I could implemnt it quickly.

 

This post originally appeared on the Stronico blog – with the absorption of Stronico into Digital Tool Factory this post has been moved to the Digital Tool Factory blog


24
May 11


Written By Steve French

 

How to Fix the “Service Unavailable” problem in IIS

Gears gears cogs bits n piecesThe Problem: For whatever reason, your website is displaying a white screen with “Service Unavailable” and nothing else.

The Cause: There could be many causes, but the one I just discovered was that the application pool had shut down for no good reason.

The Solution: In IIS, navigate to “Application Pools”, right click to bring up the content manager – select “Stop”, and then select “Start”.  That should fix the problem in most cases.

Creative Commons License photo credit: Elsie esq.

 

This post originally appeared on the Stronico blog – with the absorption of Stronico into Digital Tool Factory this post has been moved to the Digital Tool Factory blog


23
May 11


Written By Steve French

 

How to create a asp.net gridview hyperlink field with multiple querystring parameters

Frozen linksThe Problem: You need to put a relatively complicated link (i.e. the link has more than one parameter) into an asp.net gridview column.

The Cause: No cause really, you just need to know the exact syntax
The Solution:

<asp:HyperLinkField HeaderText=””

Text=”Download Your File”

DataNavigateUrlFields=”CategoryID,FileID”

DataNavigateUrlFormatString=”FileDownloader.

aspx?catid={0}&file={1}” />

You can have as many fields as you like in the DataNavigateUrlFields tag, and it will simply autopopulate from that point on (provided you have the parameters in proper {0} fashion.  This is hardly the biggest problem I’ve ever faced, but I didn’t know how to create the Hyperlink field in that way and now I do.
Creative Commons License photo credit: skedonk

 

This post originally appeared on the Stronico blog – with the absorption of Stronico into Digital Tool Factory this post has been moved to the Digital Tool Factory blog


19
May 11


Written By Steve French

 

An argument for .Net in startups – to wit, avoiding groupthink

Vikings!I recently read Why Startups Could Use .NET, But Don’t and the original CEO Friday: Why we don’t hire .NET programmers post from Expensify.  For a quick summary

Starting Fact:

  • Startups are risk taking places
  • Startups are founded by risk taking people

Pros of .Net

  • Great Tools
  • Works together well
  • .Net programmers know how to use the platform

Cons of .Net

  • .Net programmers are stodgy
  • And risk averse
  • And see no need to tweak solved problems like the networking stack

(Granted, I am biased as a .net developer.)

From which I drew the conclusion: The technology is, if anything, better, but the non .Net people are more similar to risk-taking startup CEO types, so they fit into the startup culture much better.

Now that I think about it, that seems to be an argument FOR startups developing on the .Net platform.  The risk taking CEO is a given, if you also bring in like-minded developers then the startup will have more group think, and consequently make poorer decisions than a more diverse mix of personalities.

Now that I read this again, this is an empirical question – What proportion of .Net based startups reach profitability vs the non .Net startups?  Do(es) the data exist anywhere?

Creative Commons License photo credit: hans s

 

This post originally appeared on the Stronico blog – with the absorption of Stronico into Digital Tool Factory this post has been moved to the Digital Tool Factory blog


17
May 11


Written By Steve French

 

Fix the problem and move on

I recently ate breakfast with a few other local business types (one the head of the best event staffing company in Atlanta) and one of them presented an interesting problem.  He told the story of a former staff member who had made what seemed (to him)  to be an obvious mistake.  He seemed to think that this was caused by an inborn flaw that could never be fixed.  The dilemma, should he have gotten rid of the staffer or worked around the staffer?   The majority of people agreed with the inborn flaw theory, but that he should just work around the flaw.

I thought that the problem was fundamental attribution error, (attributing the problem to the person and not the situation).  He thought that the former staffer possessed no initiative.  My initial thought (from his description of the situation) was that the staffer was confronted with an unclear situation and he had no obvious way to show initiative.

Upon further thought,  in real world situations, there is no way to ever determine which one of us is right, and the best thing to do it just put the solution to the problem in a checklist or manual and move on.

 

This post originally appeared on the Stronico blog – with the absorption of Stronico into Digital Tool Factory this post has been moved to the Digital Tool Factory blog


16
May 11


Written By Steve French

 

How to fix problems with asp.net mvc 3 charts and razor pages

The Problem: You attempt to use the super-cool new charting features in asp.net mvc 3, and all you get is compilation errors

The Cause: You are using the old school System.Web.UI.DataVisualization.Charting.Chart namespace

The Solution: Delete

using System.Web.UI.DataVisualization.Charting.Chart

and instead insert

using System.Web.Helpers;

If you are using the chart code in an actual razor page (and not in the controller), just insert

@using RazorHelpers.Helpers

into the top of the page

 

This post originally appeared on the Stronico blog – with the absorption of Stronico into Digital Tool Factory this post has been moved to the Digital Tool Factory blog


06
May 11


Written By Steve French

 




Copyright 2011 Digital Tool Factory. All Rights Reserved. Powered by raw technical talent. And in this case, WordPress.