Monday, September 27, 2010

“Razor” – a new view engine for ASP.NET

Razor” – a new view engine for ASP.NET developed by Microsoft.

The new view-engine option have been working on is optimized around HTML generation using a code-focused templating approach. The codename for this new view engine is “Razor”,

Microsoft had a number of design goals when building and testing Razor, attempting to create a compact, expressive, and fluid ASP.NET view engine.

In addition, the Redmond company worked to ensure that customers would be able to leverage Razor immediately, by using their existing language and HTML skills.

Design Goals for "Razor"

Sunday, September 26, 2010

Access Properties of a UserControl from other UserControl in ASP.Net Page

Few days ago I have posted an article "How To Access One UserControl from Another UserControl Using ASP.NET". When I try to find out solution for this I have got some nice articles about this issue. Rami vermula shows how to access properties of UserControl from another UserControl In asp.net.

This is really very helpful to solved my problem and immedidately me implement it in my solution.Now share for you .....

WebUserControl1.ascx
===================
This is the first UserControl on the page, from which we access the other UserControl (WebUserControl2.ascx) Properties.

Code
======

Automatic URL re-basing in the HtmlHead control

If you're using Master Pages in ASP.NET and trying to resolve <script> or <style> references in the page head, you may have run into this this show-stopper. If so, here's why it's happening, and here's an easy way to fix it.

If you've worked with ASP.NET Master Pages, you've no doubt taken advantage of automatic URL re-basing within the HtmlHead control. This bit of ASP.NET magic helps assure that a content page has access to the correct resources:

<head id="head1" runat="server">
<title>My Page</title>
<link href="css/common.css" rel="stylesheet" type="text/css" />
</head >

When you add the runat="server" attribute to the tag,

Thursday, September 23, 2010

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Server Error in 'ASP.Net' Application.

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
____________________________________________________________________________

Recently I have faced this type of error on browse my application after add JavaScript method. This is the first time I have faced this issue. Newly written method is double checked by me but nothing found. Then try to find in asp.net forum now this time got the solution :).

Very silly mistake......now I have share with you.

Wednesday, September 22, 2010

DateTime Custom Picture Formatting

Using Picture Formats for Custom Formatting

The standard format specifiers are useful in most cases whilst still maintaining the correct style of date and time for the user's location. On some occasions however, it is necessary to have complete control over the positioning and styling of each element of date and time information.

For this, picture formats must be used. These allow an exact format to be created using any combination of elements from a DateTime.

DateTime theDate = DateTime.Parse("3 Jan 2007 21:25:30");
string result;

result = theDate.ToString("d-MM-yy");//result ="3-01-07"
result = theDate.ToString("HH:mm");//result ="21:25"
result = theDate.ToString("h:mm tt");//result ="9:25 PM"

Available Picture Formatting Codes

The above example shows several formats and the results. The full list of available formatting codes is as follows:
SpecifierDescriptionExamples
yOne-digit year. If the year cannot be specified in one digit then two digits are used automatically."7"
"95"
yyTwo-digit year with leading zeroes if required."07"
yyyyFull four-digit year."2007"
g or ggIndicator of Anno Domini (AD)."A.D."
MOne-digit month number. If the month cannot be specified in one digit then two digits are used automatically."1"
"12"
MMTwo-digit month number with leading zeroes if required."01"
MMMThree letter month abbreviation."Jan"
MMMMMonth name."January"
dOne-digit day number. If the day cannot be specified in one digit then two digits are used automatically."3"
"31"
ddTwo-digit day number with leading zeroes if required."03"
dddThree letter day name abbreviation."Wed"
ddddDay name."Wednesday"
hOne-digit hour using the twelve hour clock. If the hour cannot be specified in one digit then two digits are used automatically."9"
"12"
hhTwo-digit hour using the twelve hour clock with leading zeroes if required."09"
HOne-digit hour using the twenty four hour clock. If the hour cannot be specified in one digit then two digits are used automatically."1"
"21"
HHTwo-digit hour using the twenty four hour clock with leading zeroes if required."09"
tSingle letter indicator of AM or PM, generally for use with twelve hour clock values."A"
"P"
ttTwo letter indicator of AM or PM, generally for use with twelve hour clock values."AM"
"PM"
mOne-digit minute. If the minute cannot be specified in one digit then two digits are used automatically."1"
"15"
mmTwo-digit minute with leading zeroes if required."01"
sOne-digit second. If the second cannot be specified in one digit then two digits are used automatically."1"
"59"
ssTwo-digit second with leading zeroes if required."01"
fFraction of a second. Up to seven f's can be included to determine the number of decimal places to display."0"
"0000000"
zOne-digit time zone offset indicating the difference in hours between local time and UTC time. If the offset cannot be specified in one digit then two digits are used automatically."+6"
"-1"
zzTwo-digit time zone offset indicating the difference in hours between local time and UTC time with leading zeroes if required."+06"
zzzFull time zone offset indicating the difference in hours and minutes between local time and UTC time with leading zeroes if required."+06:00"

Some of the formatting codes use the same letter as a format specifier. When used within a format string that is greater than one character in length this does not present a problem.

If you need to use a single character picture format string, the letter must be preceded by a percentage sign (%) to indicate that the standard format specifier is not to be used.

DateTime theDate = DateTime.Parse("3 Jan 2007 21:25:30");
string result;

result = theDate.ToString("d");// result = "03/01/2007"
result = theDate.ToString("%d");// result = "3"

How To Access One UserControl from Another UserControl Using ASP.NET

Few days ago, I need to access one UserControlfrom to another UserControl.The scenario is like,When I press a button it will assign a value from UserControl-1's TextBox to UserControl-2's TextBox. I have developed it but I made a silly mistake so that it was not working.

Now this is the time turn to google......:). Fortunately I have got almost similar solution from KaushaL PariK(MVP). Very simple.....from his solution I found out my problem....now place this here for you guys....hope that you enjoy it.

Some known tips

Missing debug menu on Visual Studio 2008

Before using Visual Studio 2010 I had usually developed application in Visual studio 2008. I don't remember, for some reason I can't find debug menu on my VS 2008. After goggling I have found the solution. I would like to share with you. It may help other guys.

Its very simple just use it:

Run "devenv /resetskippkgs" from command prompt, it will solve your problem.

"It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level" in asp.net

Very recently, I have got this error message when try to browsing my developed application in asp.net. So I try to solve in many ways but failed then move to google...:). I got some nice solutions...now share with you:

This error occurs primarily out of 2 scenarios.

First scenario:

When you create an new web application using visual studio.net, it automatically creates the virtual directory and configures it as an application.

However, if you manually create the virtual directory and it is not configured as an application, then you will not be able to browse the application and may get the above error. The debug information you get as mentioned above, is applicable to this scenario.

Method 'StartWorkflowOnListItem' in type 'Microsoft.SharePoint.WorkflowServices.FabricWorkflowInstanceProvider'

Exception: Method 'StartWorkflowOnListItem' in type 'Microsoft.SharePoint.WorkflowServices.FabricWorkflowInstanceProvider'...