Thursday, January 27, 2011

How to refresh Intellisense in SQL Server 2008

Intellisense in SQL Server 2008 Management Studio is a great feature. When adding a table, column etc, your Intellisense doesn't know about the change right away.

To fix this

Edit > Intellisense > Refresh Local Cache

Thursday, January 20, 2011

How to find the value of a dropdown in a user control using jQuery

you may have an asp:Dropdown control with an id="ddViewBy" like below.

<asp:DropDownList class="ddList" runat="server" ID="ddViewBy" AutoPostBack="true" OnSelectedIndexChanged="ddViewBy_Changed"><asp:DropDownList>

If your dropdownlist is in a user control and the usercontrol is in a content place holder, then when you view source, on the web page the id of the control would change to something like this:

id="ctl00_phContent_ucSearchFilter_ddViewBy"

To find the value of the dropdown using jQuery, use the following selector

$('select[id$=ddViewBy]').val();

This is reliable, because your user control could be in different place holders which would cause the first part of the id to be different. The controls id will always end with your original name.

The $= means "ends with"

Just an FYI, ^= means "begins with"


Wednesday, January 19, 2011

How to create the ASP.Net membership tables

Sometimes web hosts (such as godaddy) will set up the aspnet membership tables for you in your database as part of the setup.

When you need to set them up locally, use the following .Net framework command
//For servername you can use "(local)" if the database is a local SQL Server install
System.Web.Management.SqlServices.Install(txtServer.Text, txtUserName.Text, txtPassword.Text, txtDatabase.Text, SqlFeatures.All);

Monday, November 29, 2010

How to strip non-alphanumeric chars from a string

The example below also leaves the space character and commas intact.

      private string StripSpecialChars(string inputString)
{
return (Regex.Replace(StripHTML(inputString), "[^A-Za-z0-9 ,]", ""));
}

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

When I create e-commerce sites, the order numbers always start at 1. My customers like to pretend that they've had lots of orders when they launch, so I need to update their order number to something higher. The problem is this is always the identity field of the table. This command does the trick. It doesn't update the old order numbers, but I don't need those updated so it's no big deal.

DBCC CHECKIDENT('order', RESEED, 1000070 )