Saturday, June 16, 2007

Using a Master Page in ASP.net

The easiest & quickest way to get on with Master Pages

Creating a Master Page :

  1. Create an aspx page, as you want the basic layout to be.
  2. Add a new Master Page to your web app.
  3. Copy all code from aspx page created in step 1, exclude @Page tag
  4. Paste everything by replacing default code in MasterPage, keep @Page tag as it is
  5. Wherever you want content to appear from content pages, place a <asp:contentplaceholder> control
  6. Master page is ready now
The above method helps in previewing changes easily, though a master page can be created directly without using an aspx page first, and can be previewed using a content page.

Using a Master Page :

  1. Add a WebContentForm to web app.
  2. if its a web project, you will have to select WebForm and check 'select master page' check box while adding this page.
  3. Select the master page for this page. That's it!
If a page already exist and you want to convert it to a content page, add "MasterPageFile" attribute in @Page directive of the wannabe content page and remove all html code from this page and pace <asp:content> control and the code you want to appear in content area.

Thursday, June 14, 2007

SQL Server Error : 'function_name' is not a recognized name

A silly issue, but may bug you if you are not a regular sql server udf user.

Whenever a scalar-valued user defined function is invoked just using the name of the function, single part, you will get an error like -

Msg 195, Level 15, State 10, Line 1
'function_name' is not a recognized function name.

To resolve this use at least two part function name (by prefixing it with owner).
example :
(1) Select MyScalarFunction() -- wrong usage
(2) Select dbo.MyScalarFunction() -- correct usage


Important thing to note is that table-valued function, unlike scalar-valued, can be called using single part name.

Tip: to avoid using multi part naming in sql server 2005, you can use synonyms.

[more reading on user defined functions]

Monday, June 11, 2007

Sending Email using .NET : FAQ

Sending an email using .NET is very easy and is just few lines of code. So not much of a trouble in coding it. But, actual problem starts when one tries to run it and specially on a new / non configured SMTP server. Debugging these few lines can make anyone go crazy as there is not much to do and can take days to be resolved.

Though we have a detailed documentation on MSDN and good examples, I would like to mention here another very good resource for FAQ on sending email - www.systemnetmail.com. This website hosts a detailed FAQ which you comes really handy while resolving email related issues.

In .NET 2.0, we use classes in System.Net.Mail namespace for this purpose and hence the name comes - 'systemnetmail.com'. For .NET 1.1 we had System.Web.Mail and, yes you guessed it, we have www.systemwebmail.com for referring to old style of sending email.

Overall, a nice and handy email FAQ compilation from Dave Wanta.