private string StripSpecialChars(string inputString)
{
return (Regex.Replace(StripHTML(inputString), "[^A-Za-z0-9 ,]", ""));
}
Monday, November 29, 2010
How to strip non-alphanumeric chars from a string
How to strip HTML tags out of a string
static string StripHTML(string inputString)
{
return Regex.Replace
(inputString, "<.*?>", string.Empty);
}
Saturday, November 13, 2010
How to reseed an identity field
DBCC CHECKIDENT('order', RESEED, 1000070 )
Tuesday, October 19, 2010
How to set the selected item in an MVC Dropdownlist
The first parameter to the Html.DropDownList needs to be a name that does not match the name in your model. Below I used "OptionId" instead of "Options".
View
<%= Html.DropDownList("OptionId",Model.Options) %>
Controller
SelectListItem item1 = new SelectListItem();
item1.Text = "Red";
item1.Value = "Red";
item1.Selected = false;
viewModel.Options.Add(item1);
SelectListItem item2 = new SelectListItem();
item2.Text = "Green";
item2.Value = "Green";
item2.Selected = true;
viewModel.Options.Add(item2);
SelectListItem item3 = new SelectListItem();
item3.Text = "Blue";
item3.Value = "Blue";
item3.Selected = false;
viewModel.Options.Add(item3);
Tuesday, October 5, 2010
How to create a modal dialog in jQuery and prevent scrolling in background
$(document).ready(function() {
$("#dialog").dialog({ autoOpen: false
, modal: true
, buttons:
{
"Cancel": function() {
$(this).dialog("close");
$("body").css("overflow", "auto"); }
, "Save": function() {
$(this).dialog("close");
$("body").css("overflow", "auto"); }
}
});
});
function RenameFile(filename, id) {
$("#OldFilename").html("From: " + filename);
$("#NewFilename").val(filename);
$("#dialog").dialog("open");
$("body").css("overflow", "hidden");
}
<div id="dialog" title="Change Filename">
<p id="OldFilename"><b>From: </b>oldfilename.doc</p>
<p><b>To: </b>
<input id="NewFilename" type="text" style="width:200px" /></p>
</div>
<a style="cursor:hand;text-decoration:underline;color:Blue" onclick="javascript:RenameFile('<%= Html.Encode(doc.FileName) %>',<%= doc.PathID %>)">rename</a>
Wednesday, September 29, 2010
How to resolve unresolved type System.Web.Security.MembershipCreateStatus which appears after converting from vs2008 to vs2010
Thursday, September 23, 2010
How to add a configuration file to your class library
Wednesday, September 22, 2010
How to insert a tab in Microsoft Word when your cursor is in a table cell
When you want to insert a tab, use [Ctrl][Tab] instead
Tuesday, September 21, 2010
How to create FREE flowcharts online
Monday, September 20, 2010
How to display hidden files and folders in Windows 7
How to use a hidden input in MVC
<p class="display_currency"><span id="totalprice">$0.00</span></p><%= Html.HiddenFor(m=>m.TotalOrder) %>
$("#TotalOrder").val(total.toFixed(2)); //hidden control for model
Saturday, September 18, 2010
How to copy color syntax from VS2010 to Blogger
switch (pricedisplaytype)
{
case (int)ProductPriceDisplayType.DontShowPrice:
item.ItemTitle = description;
break;
case (int)ProductPriceDisplayType.ShowPriceEach:
item.ItemTitle = String.Format("{0} (${1:n3} each)", description, qty.Price / qty.Quantity);
break;
case (int)ProductPriceDisplayType.ShowTotalPrice:
item.ItemTitle = String.Format("{0} (${1:n2})", description, qty.Price);
break;
}
How to select a radio button in JQuery
function SetRadioButtonValueToThree()
{
$( "#radiobtn_3" ).attr( "checked" , "checked" );
}
<input type= "radio" name= "myradioGroup" id= "radiobtn_1" value= "1" checked= "checked" />One<br/>
<input type= "radio" name= "myradioGroup" id= "radiobtn_2" value= "2" />Two<br/>
<input type= "radio" name= "myradioGroup" id= "radiobtn_3" value= "3" />Three<br/>
How to create HTTP POST and GET methods with the same signature
[ActionName( "UploadArtwork" )]
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult UploadArtworkGet(string dataMyComponentUses)
{
...
return View( "UploadArtwork" );
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UploadArtwork(string dataMyComponentUses)
{
...
return View( "UploadArtwork" );
}
How to return a pdf file in MVC (instead of preview by browser)
public ActionResult GetPDF(string filename)
{
return File(filename, "application/pdf" , Server.HtmlEncode(filename));
}