How to use JQuery with Master Pages?

EDIT As @Adam points out in the comments, there is a native jQuery mechanism that basically does the same thing as the hack in my original answer. Using jQuery you can do $(‘[id$=myButton]’).click(function(){ alert(‘button clicked’); }); My hack was originally developed as a Prototype work around for ASP.NET and I adapted it for the original … Read more

How can I show a viewbag as html?

Everyone is correct in the use of @Html.Raw() but I want to point out to be careful with this, as it can make your site susceptible to XSS vulnerabilities. I would combine the @Html.Raw(ViewBag.SomeMessage) with Microsoft’s Anti-XSS Library to make sure you do not introduce any vulnerabilities from this. Edit: The advantage of the Anti-XSS … Read more

Formatting DataBinder.Eval data

There is an optional overload for DataBinder.Eval to supply formatting: <%# DataBinder.Eval(Container.DataItem, “expression”[, “format”]) %> The format parameter is a String value, using the value placeholder replacement syntax (called composite formatting) like this: <asp:Label id=”lblNewsDate” runat=”server” Text=”<%# DataBinder.Eval(Container.DataItem, “publishedDate”, “{0:dddd d MMMM}”) %>”</label>

How to create Select List for Country and States/province in MVC

public static List<SelectListItem> States = new List<SelectListItem>() { new SelectListItem() {Text=”Alabama”, Value=”AL”}, new SelectListItem() { Text=”Alaska”, Value=”AK”}, new SelectListItem() { Text=”Arizona”, Value=”AZ”}, new SelectListItem() { Text=”Arkansas”, Value=”AR”}, new SelectListItem() { Text=”California”, Value=”CA”}, new SelectListItem() { Text=”Colorado”, Value=”CO”}, new SelectListItem() { Text=”Connecticut”, Value=”CT”}, new SelectListItem() { Text=”District of Columbia”, Value=”DC”}, new SelectListItem() { Text=”Delaware”, Value=”DE”}, new … Read more