Wednesday, August 3, 2011

YOU LIVE ONLY ONCE.............

An elderly man in Mumbai calls his son in New York and says,

'I hate to ruin your day son, but I have to tell you that your mother and I are getting a divorce; 35 years of marriage... and that much misery is enough!'

'Dad, what are you talking about?' the son screams.

'We can't stand the sight of each other any longer,' the old man says.

'We're sick of each other, and I'm sick of talking about this, so you call your sister in Hong Kong and tell her!'

Frantic, the son calls his sister, who explodes on the phone.

'Like heck they're getting divorced,' she shouts, 'I'll take care of this.'


She calls Mumbai immediately, and screams at the old man, 'You are not getting divorced. Don't do a single thing until I get there. I'm calling my brother back, and we'll both be there tomorrow. Until then , don't do a thing, DO YOU HEAR??' and she hangs up.


The old man hangs up his phone and turns to his wife. 'Okay', he says, 'It's all set. They're both coming for our anniversary and paying their own airfare!!'



MORAL:

No man / woman is busy in this world all 365 days.

The sky is not going to fall down if you take few days LEAVE and meet your dear ones.

OFFICE WORK IS NOT EVERYTHING IN LIFE and MONEY MAKING IS NOT EVERYTHING IN LIFE.

10 Rules for Driving on Indian Roads

Alright people, print this out and stick it on a wall in front of your desk. Print bumper stickers if you like. Forward this to all friends, foes and colleagues.


The following tips will save your life. They will make you the king of Indian roads. Nobody will ever overtake you again. Not in life. Not on the road. Here’s 10 rules for driving on Indian roads. Based on careful analysis derived from personal experiences, market research and interviews, primarily with myself.

Read, and remember. And rule.

1. In a road accident, the one with the cheaper vehicle wins by default. If a BMW hits a rickshaw, it must be the fault of the rich brat most likely on cocaine.

2. It is perfectly acceptable to suddenly go across 3 lanes if you suddenly remember that you need to take a right turn. What else will you do?

3. Drunk driving is fine, as long as you have the connections.

4. If at an intersection you fail to move within a second of the light turning green, the person behind has the right to shoot you.

5. Backing down halfway from flyovers is acceptable.

6. If going wrong side saves you anything more than 200m worth of distance, then it is allowed. Rickshaws are exempted from this limit.

7. No rules apply to motorbikes. Really. Overtake from any side. Drive on the road. On the pavement. Over people. It is all ok.

8. Cyclists must pray to their respective gods before leaving the home. No other way out.

9. When in doubt, use the horn. [Which truly must be the best human invention since the mobile phone.]

10. Work like you don’t need money, Love like you’ve never been hurt, dance like no one’s watching, and drive like no one’s waiting back home.

LUCK Matters !!!

LUCK Matters !!!

With a pile of 300 resumes on his desk and a need to pick someone quickly, my boss told me to make calls on the bottom 50 and toss the rest.
"Throw away 250 resumes?" I asked, shocked.

"What if the best candidates are in there?"
"You have a point," he said.
"But then again, I don't need people with bad luck here."

:O

Tuesday, November 9, 2010

$500 million for Diaper and Soap

How much you can spend on a diaper and a soap ??

Jeff Bezos CEO of Amazon spend half a billion for that. Confused ??

Amazon acquires Diaper.com, Soap.com for $500 million. got this article delivered in my inbox from ZDnet.com and what I like most in that is the statement of Bezos

I’m not sure which is more unpleasant–changing diapers, paying too much for them, or running out of them

Amazon on Monday officially acquired Quidsi, the company that operates Diaper.com and Soap.com for $500 million in cash. Amazon also assumes $45 million in Quidsi debt.

According to Amazon, Quidsi will continue to be and independent venture run by its current management team. That blueprint was established when Amazon bought Zappos. The Quidsi deal is expected to close in December.

Thursday, August 5, 2010

New Indian Rupee Coin

Sunday, July 18, 2010

The Indian Rupee gets a new symbol

Now, Indian Rupee have its own unique symbol like Dollars, Euros and Yen. The new symbol had been drawn by an IIT post-graduate D Udaya Kumar.

Out of 3,000 designs that were competing for the symbol, Kumar’s drawing had been chosen by the Union Cabinet meeting held on July 15, 2010, chaired by Manmohan Singh, Indian Prime Minister. He would get a prize money of Rs.2,50,000 from the Finance Ministry.







The new symbol is an amalgam of the Devnagiri ‘Ra’ and Roman capital ‘R’ without the stem.

The government will try to adopt the new symbol within six months in the country and globally within the next two years.

The new Rupee symbol will be included in the “Unicode Standard” for representation and processing of text, written in major scripts of the world to ensure that the Rupee symbol is easily displayed/printed in the electronic and print media as all the software companies provide support for this Standard.



Encoding in the Unicode Standard will also ensure encoding in the International standard ISO/IEC 10646 as both the organizations work closely with each other.

The encoding of the rupee symbol in the Indian Standards is estimated to take about six months while encoding in the Unicode and ISO/IEC 10646 will take about 18 months to two years. It will be incorporated in software packages and keyboards in use in India.



download font from here

http://alturl.com/3yy5r

Friday, July 9, 2010

SQL SERVER – UDF – Function to Convert Text String to Title Case – Proper Case

Following function will convert any string to Title Case. I have this function for long time. I do not remember that if I wrote it myself or I modified from original source.

Run Following T-SQL statement in query analyzer:

SELECT dbo.udf_TitleCase('convert this string to title case!')


The output will be displayed in Results pan as follows:



Convert This String To Title Case!


T-SQL code of the function is:



CREATE FUNCTION udf_TitleCase (@InputString VARCHAR(4000) )
RETURNS VARCHAR(4000)
AS
BEGIN
DECLARE @Index INT
DECLARE @Char CHAR(1)
DECLARE @OutputString VARCHAR(255)
SET @OutputString = LOWER(@InputString)
SET @Index = 2
SET @OutputString =
STUFF(@OutputString, 1, 1,UPPER(SUBSTRING(@InputString,1,1)))
WHILE @Index <= LEN(@InputString)
BEGIN
SET @Char = SUBSTRING(@InputString, @Index, 1)
IF @Char IN (' ', ';', ':', '!', '?', ',', '.', '_', '-', '/', '&','''','(')
IF @Index + 1 <= LEN(@InputString)
BEGIN
IF @Char != ''''
OR
UPPER(SUBSTRING(@InputString, @Index + 1, 1)) != 'S'
SET @OutputString =
STUFF(@OutputString, @Index + 1, 1,UPPER(SUBSTRING(@InputString, @Index + 1, 1)))
END
SET @Index = @Index + 1
END
RETURN ISNULL(@OutputString,'')
END

Friday, May 28, 2010

Extensible Request Validation

ASP.NET request validation searches incoming HTTP request data for strings that are commonly used in cross-site scripting (XSS) attacks. If potential XSS strings are found, request validation flags the suspect string and returns an error. The built-in request validation returns an error only when it finds the most common strings used in XSS attacks. Previous attempts to make the XSS validation more aggressive resulted in too many false positives. However, customers might want request validation that is more aggressive, or conversely might want to intentionally relax XSS checks for specific pages or for specific types of requests.

In ASP.NET 4, the request validation feature has been made extensible so that you can use custom request-validation logic. To extend request validation, you create a class that derives from the new System.Web.Util.RequestValidator type, and you configure the application (in the httpRuntime section of the Web.config file) to use the custom type. The following example shows how to configure a custom request-validation class:

<httpRuntime requestValidationType="Samples.MyValidator, Samples" />



The new requestValidationType attribute requires a standard .NET Framework type identifier string that specifies the class that provides custom request validation. For each request, ASP.NET invokes the custom type to process each piece of incoming HTTP request data. The incoming URL, all the HTTP headers (both cookies and custom headers), and the entity body are all available for inspection by a custom request validation class like that shown in the following example:



public class CustomRequestValidation : RequestValidator
{
protected override bool IsValidRequestString(
HttpContext context, string value,
RequestValidationSource requestValidationSource,
string collectionKey,
out int validationFailureIndex)
{...}
}

For cases where you do not want to inspect a piece of incoming HTTP data, the request-validation class can fall back to let the ASP.NET default request validation run by simply calling base.IsValidRequestString.

Expanding the Range of Allowable URLs

ASP.NET 4 introduces new options for expanding the size of application URLs. Previous versions of ASP.NET constrained URL path lengths to 260 characters, based on the NTFS file-path limit. In ASP.NET 4, you have the option to increase (or decrease) this limit as appropriate for your applications, using two new httpRuntime configuration attributes. The following example shows these new attributes.

<httpRuntime maxRequestPathLength="260" maxQueryStringLength="2048" />




To allow longer or shorter paths (the portion of the URL that does not include protocol, server name, and query string), modify the maxRequestPathLength attribute. To allow longer or shorter query strings, modify the value of the maxQueryStringLength attribute.



ASP.NET 4 also enables you to configure the characters that are used by the URL character check. When ASP.NET finds an invalid character in the path portion of a URL, it rejects the request and issues an HTTP 400 error. In previous versions of ASP.NET, the URL character checks were limited to a fixed set of characters. In ASP.NET 4, you can customize the set of valid characters using the new requestPathInvalidChars attribute of the httpRuntime configuration element, as shown in the following example:



 



<httpRuntime requestPathInvalidChars="&lt;,&gt;,*,%,&amp;,:,\,?"  />




By default, the requestPathInvalidChars attribute defines eight characters as invalid. (In the string that is assigned to requestPathInvalidChars by default, the less than (<), greater than (>), and ampersand (&) characters are encoded, because the Web.config file is an XML file.) You can customize the set of invalid characters as needed.

Permanently Redirecting a Page

It is common practice in Web applications to move pages and other content around over time, which can lead to an accumulation of stale links in search engines. In ASP.NET, developers have traditionally handled requests to old URLs by using by using the Response.Redirect method to forward a request to the new URL. However, the Redirect method issues an HTTP 302 Found (temporary redirect) response, which results in an extra HTTP round trip when users attempt to access the old URLs.

ASP.NET 4 adds a new RedirectPermanent helper method that makes it easy to issue HTTP 301 Moved Permanently responses, as in the following example:

RedirectPermanent("/newpath/foroldcontent.aspx");

ClientIDMode in ASP.NET 4.0

One of the more anticipated features of ASP.NET 4.0 – is the new ClientIDMode property, which can be used to force controls to generate clean Client IDs that don’t follow ASP.NET’s munged NamingContainer ID conventions. To be clear, NamingContainer IDs are necessary for complex controls and pages that nest many things inside of a single context, but for most application level Web design scenarios those munged IDs get in the way and don’t provide a lot of value.

The munged IDs affect all sorts of development scenarios from design and CSS styling where ID haven’t been predictable for #id styling:

#ctl00_content_txtName 
{
font-weight: bold;
}



vs the more expected:



#txtName
{
font-weight: bold;
}



And even more so there’s the whole nightmare of ClientIds in script pages where code like this:



<script type="text/javascript">
var txtName = $("<%= txtName.ClientID %>");
var txtTitle = $("[id$=_txtTitle]");
</script>



or some other pre-generation code is necessary to get client id’s properly referenced in script code.



ClientIDMode


In prior versions of ASP.NET you had to live with the problem or work around with various hacks. In ASP.NET 4.0 things get a little easier via the new ClientIDMode property which allows you to specify exactly how a ClientID is generated.



The idea is simple: you get a new ClientIDMode property on all ASP.NET controls which can be set either at the actual control or somewhere up the NamingContainer chain. If the ClientIDMode property is not set on a control it inherits the setting from the nearest NamingContainer with the exception of  the <asp:Content> placeholder which doesn’t participate in ClientIDMode processing (bummer!).



This means if you choose to you can set ClientIDMode on the Page level and it will trickle down into all the child controls on the page, but a custom naming container like a User Control can still override the ClientIDMode to enforce it’s naming container requirements. It’ll be interesting to see how much existing code might break based on this inheritance scheme as custom controls may lose controls over their ClientID naming if the ClientIDMode property isn’t set explicitly.



Anyway let’s take a look at a very simple example and how the ClientIDMode property affects the ID rendering. Imagine you have a page that uses a master page and is set up like this:



<%@PageTitle=""Language="C#"MasterPageFile="~/Site.Master"AutoEventWireup="true" 
CodeBehind="WebForm2.aspx.cs"
Inherits="WebApplication1.WebForm2"
ClientIDMode="Predictable"
%>

<asp:ContentID="content"ContentPlaceHolderID="content"runat="server"ClientIDMode="Static" >
<asp:TextBox runat="server"ID="txtName"ClientIDMode="Static" />
</asp:Content>



Here’s what the various values for the txtName property can look like:



AutoID



This is the existing behavior in ASP.NET 1.x-3.x where full naming container munging takes place.



<input name="ctl00$content$txtName" type="text" id="ctl00_content_txtName" />



In Beta 2 this is the default value for the Page. According to the latest VS 2010 documentation however, the default behavior by release time will be Predictable.



Static

This option forces the control’s ClientID to use its ID value directly. No naming container naming at all is applied and you end up with clean client ids:



<inputname="ctl00$content$txtName"type="text"id="txtName" />



This option is what most of us want to use, but you have to be clear on that this can potentially cause conflicts with other control on the page. If there are several instances of the same naming container (several instances of the same user control for example) there can easily be a client ID naming conflict. It’s basically up to you to decide whether this is a problem or not.



Note that if you assign Static to a Databound control like a list child controls in templates do not get unique IDs either, so for list controls where you rely on unique Id for child controls you’ll probably want to use Predictable rather than Static. More on this a little later when I discuss ClientIDRowSuffix.



Predictable



The previous two values are pretty self-explanatory. Predictable however, requires some explanation. To me at least it's not in the least bit predictable :-}.

MSDN defines this enum value as follows:




This algorithm is used for controls that are in data-bound controls. The ClientID value is generated by concatenating the ClientID value of the parent naming container with the ID value of the control. If the control is a data-bound control that generates multiple rows, the value of the data field specified in the ClientIDRowSuffix property is added at the end. For the GridView control, multiple data fields can be specified. If the ClientIDRowSuffix property is blank, a sequential number is added at the end instead of a data-field value. Each segment is separated by an underscore character (_).




The key that makes this value a bit confusing is that it relies on the parent NamingContainer’s ClientID to build it’s own client ID value. Which effectively means that the value is not predictable at all but rather very tightly coupled to the parent naming container’s ClientIDMode setting.



For our simple textbox example, if the ClientIDMode property of the parent naming container (Page in this case) is set to “Predictable” you’ll get this:



<input name="ctl00$content$txtName" type="text" id="content_txtName" />



which gives a name that walk up to the currently active naming container (the MasterPage content container) and starts the name from there downward. Think of this as a semi unique name that’s guaranteed unique only for the naming container.

If on the other hand the Page is set to “AutoID” you get with Predicable on txtName:



<input name="ctl00$content$txtName" type="text" id="ctl00_content_txtName" />



The latter is effectively the same as if you specified AutoID in this scenario because it inherits the AutoID naming from the Page and Content control of the page.  But again – predictable behavior always depends on the parent naming container and how it generates its id so the ID may not always be exactly the same as the AutoID generated value because somewhere in the NamingContainer chain the ClientIDMode setting may be set to a different value. For example if you had another naming container in the middle that was set to Static you’d end up effectively with an ID that starts with the NamingContainers' ID rather than the whole ctl000_content munging.



The most common use however for Predictable will be for DataBound controls, which results in a each data bound item to get a unique ClientID.



Predictable is useful, but only if all naming containers down the chain use this setting. Otherwise you’re right back to the munged Ids that are pretty unpredictable.



Inherit



The final setting is Inherit which is the default for all controls except Page (AFAIK). This means that controls by default inherit the naming container’s ClientIDMode setting.



Inheritance


The explicit values are pretty obvious in what they do and when they are applied to individual controls. AutoID is classic behavior, Static is what we want in typical client centric apps, and Predictable is what you typically will want to use for list controls and anything that has possible naming conflicts.



Things get a little more tricky with inheritance of these settings. Specicfically the ClientIDMode property inherits from a NamingContainer down. Unlike most other ASP.NET hierarchy inheritance the ClientIDMode inheritance is based on the NamingContainer not on the Parent Container.



What this means is that if you set ClientIDMode="Static" on a Page or MasterPage all controls inherit that settings:



<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"          CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2"           ClientIDMode="Static" %>



If you don’t set the ClientIDMode on any other controls the entire page will use Static. Any UserControls can override the setting but all controls will use this setting.



Now imagine I do:



<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" 
CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2"
ClientIDMode="Predictable" %>



and I’m running inside of a master page and I put in a block of controls like this:



 <asp:Panel runat="server"  ClientIDMode="Static">
This is a test:
<asp:TextBox runat="server" ID="txtName" />
<asp:Button ID="btnSubmit" runat="server" Text="Go" />
</asp:Panel>



Quick what should you see? Unfortunately not what I would have expected – although it’s true to what the documentation advertises. The block above renders into:



<div>
This is a test:
<input name="ctl00$content$txtName" type="text" id="content_txtName" />
<input type="submit" name="ctl00$content$btnSubmit" value="Go" id="content_btnSubmit" />
</div>



What’s happening here is that even though we specified Static naming on the Panel (which is not a NamingContainer) Predictable naming is used which runs up to the nearest naming container – in this case the Master Page Content control and using that as its base for the name. If I want those controls to render with clean ids I need to explicitly mark the controls to use Static:



<asp:Panel runat="server"  ClientIDMode="Static">
This is a test:
<asp:TextBox runat="server" ID="txtName" ClientIDMode="Static" />
<asp:Button ID="btnSubmit" runat="server" Text="Go" ClientIDMode="Static" />
</asp:Panel>



or by changing the Page’s ClientIDMode to Static:



<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" 
CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2" ClientIDMode="Static" %>



With either of those in place I now get:



<div id="Panel1">
This is a test:
<input name="ctl00$content$txtName" type="text" id="txtName" />
<input type="submit" name="ctl00$content$btnSubmit" value="Go" id="btnSubmit" />
</div>



Notice that when page level ClientIDMode="Static" the <div> tag now renders with an explicit ID which is rather inconsistent (it’s not there if I just have ClientIDMode=”Static” on the Panel alone).



Note that you unfortunately cannot use an <asp:Content> control and specify the ClientIDMode like this:



<asp:Content ID="content" ContentPlaceHolderID="content" runat="server" ClientIDMode="Static">



This has no effect  on the controls contained inside of the Content container which still inherit the ClientIDMode from Page in this case. This is really annoying because the Content container certainly is part of the naming container hierarchy that is reflected in the ClientIDName for Predictable and AutoId.



There’s a way around this by using:




  • Static on the List Control


  • Predictable on all of the Child controls



This looks like this:



<asp:GridView runat="server" ID="gvProducts" AutoGenerateColumns="false"
ClientIDMode="Static" ClientIDRowSuffix="id"
DataSourceID="xmlDataSource"
>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label runat="server" id="txtTitle" Text='<%# Eval("title") %>' ClientIDMode="Predictable"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Label runat="server" id="txtId" Text='<%# Eval("id") %>' ClientIDMode="Predictable" />
</ItemTemplate>
</asp:TemplateField>

</Columns>
</asp:GridView>



which results in:



<table cellspacing="0" rules="all" border="1" id="Table2" style="border-collapse:collapse;">
<tr>
<th scope="col">&nbsp;</th><th scope="col">&nbsp;</th>
</tr><tr>
<td>
<span id="txtTitle_32">West Wind West Wind Web Toolkit</span>
</td><td>
<span id="txtId_32">32</span>
</td>
</tr></table>



This does produce what I would consider a desirable result although I had hoped that using Static on the list control without any further formatting would have produced this result. Unfortunately the Predictable setting on each of the child controls is required to get the clean ids into the child controls.





ClientIDRowSuffix


Another feature of the ClientID improvements in ASP.NET 4.0 is the ClientIDRowSuffix which can be applied to DataBound/List controls. I used it above in the grid to have the enumerated client id of the child controls use the value of an Id field from the database as the enumeration value. This setting basically determines how ID values for template controls in databound controls are generated, but it requires that the ClientIDMode is set to Predictable. It produces:



id="txtTitle_32"



where the _32 in this case comes from the Id of the data source which is nice than only using sequentially numbered values in previous versions of ASP.NET which were often worthless in client situations. Using an actual data value that can be looked retrieved on the client and sent back on an Ajax callback makes these IDs much more useful.



Wouldn’t it be nice if Client Row Ids could be generated?



What would be even nicer is that the generated ‘rows’ of a data bound control could optionally generate ids. In most Ajax situations the row level ID is really what’s useful – selections of rows for deletion, editing and updating always require an ID even if there are no child controls, but ASP.NET doesn’t provide an easy mechanism for embedding row ids. It sure would be get output like this:



 <tr id="content_gvProducts_33">
...
</tr>



This can be done with code in a GridView (and other list controls) with ItemCreated events it’s quite a pain to do this. For example for the gridview I’m using with a simple XmlDataSource control I have to do this:



protected void gvProducts_RowCreated(object sender, GridViewRowEventArgs e)
{
object dataItem = e.Row.DataItem;

if (dataItem != null)
{
XPathNavigator nav = ((IXPathNavigable)dataItem).CreateNavigator();
if (nav != null)
e.Row.Attributes.Add("id", this.gvProducts.ID + "_" + nav.GetAttribute("id",""));
}
}



to produce output like this:



<tr id="gvProducts_33"> ... </tr> 



which is anything but intuitive for such a common scenario (although this IS a bit easier to grab the data if you use Entity list or DataTable binding).



Data List Controls and Static Produces Invalid HTML



One more note: Using Static on list controls with child controls and NOT using Predictable for child controls is problematic as it will generate static IDs for ALL template items:



<table cellspacing="0" rules="all" border="1" id="Table1" style="border-collapse:collapse;">
<tr>
<th scope="col">&nbsp;</th><th scope="col">&nbsp;</th>
</tr><tr>
<td>
<span id="txtTitle">West Wind West Wind Web Toolkit</span>
</td><td>
<span id="txtId">32</span>
</td>
</tr><tr>
<td>
<span id="txtTitle">West Wind West Wind Web Store</span>
</td><td>
<span id="txtId">33</span>
</td>
</tr>
</table>



This is invalid HTML since there are multiple controls with the same id attribute on the page which is clearly undesirable. To fix this remember to use Predictable on any of the child controls.



Or better yet stay away from server controls altogether in template columns – stick to plain HTML controls and use AJAX to update values to the server more interactively. :-}



How should we use ClientIDMode?


I suspect it’s going to take some time to figure out all the little nuances of the new ClientIDMode features. At the very least the Static option on individual controls allows you to explicitly force controls to use the name you want it to and that’s a win any way you look at it.



For now I think the following is what I want to use in typical page scenarios in my applications:




  • Add ClientIDMode="Static" to each Page  (or in web.config’s <pages> setting)


  • Add ClientIDMode="Predictable" explicitly to each List Control Children in Databound Template


  • Override explicitly to Predictable where naming conflicts are a problem and to AutoId for the extreme edge case


  • For Control Development leave at default behavior if possible (ie. Inherit from parent)


  • Override only when necessary and preferrably on individual subcontrols



Also for now I think it’s a good idea to EXPLICITLY specify a ClientIDMode on each page (or in your project) or explicitly declare the value in your web.config file:



<pages clientIDMode="Static" />



to ensure you get a predictable setting since the current Beta 2 implementation and the documentation are at odds of what the default value actually is.

ViewStateMode in ASP.Net 4.0

 

When asp.net introduced the concept of viewstate, it changed the way how developers maintain the state for the controls in a web page. Until then to keep the track of the control(in classic asp), it was the developer responsibility to manually assign the posted content before rendering the control again. Viewstate made allowed the developer to do it with ease. The developers are not bothered about how controls keep there state on post back.

Viewstate is rendered to the browser as a hidden variable __viewstate. Since viewstate stores the values of all controls, as the number of controls in the page increases, the content of viewstate grows large. It causes some websites to load slowly.

As developers we need viewstate, but actually we do not want this for all the controls in the page. Till asp.net 3.5, if viewstate is disabled from web.config (using <pages viewstate=”false”/> ..</pages>), then you can not enable it from the control level/page level. Both <%@ Page EnableViewState=”true”…. and <asp:textbox EnableViewState=”true” will not work in this case.

Lot of developers demands for more control over viewstate. It will be useful if the developers are able to disable it for the entire page and enable it for only those controls that needed viewstate. With ASP.NET 4.0, this is possible, a happy news for the developers. This is achieved by introducing a new property called ViewStateMode.

Let us see, What is ViewStateMode – Is a new property in asp.net 4.0, that allows developers to enable viewstate for individual control even if the parent has disabled it. This ViewStateMode property can contain either of three values

  1. Enabled- Enable view state for the control even if the parent control has view state disabled.
  2. Disabled - Disable view state for this control even if the parent control has view state enabled
  3. Inherit - Inherit the value of ViewStateMode from the parent, this is the default value.

To disable view state for a page and to enable it for a specific control on the page, you can set the EnableViewState property of the page to true, then set the ViewStateMode property of the page to Disabled, and then set the ViewStateMode property of the control to Enabled.

Find the example below.

Page directive - <%@ Page Language="C#"  EnableViewState="True" ViewStateMode="Disabled" .......... %>

Code for the control  - <asp:TextBox runat="server" ViewStateMode="Enabled" ............../>

Now the viewstate will be disabled for the whole page, but enabled for the TextBox.

ViewStateMode gives developers more control over the viewstate.

Tuesday, February 2, 2010

Save time with quick computer shortcuts

If you're looking to work more efficiently in Microsoft Word, Excel, or Internet Explorer, the key is using programmed shortcuts.

To...

Use this shortcut

Select a file/folder/icon

Type the first letter of the file. If you have several files starting with the same letter, continue hitting the letter key until your cursor lands on the file or folder you want.

Search for a file/folder

F3

Rename a file/folder

Select the file/folder, click F2, and then re-type the name

Find out when the file or folder was created, by whom, and how big it is

Select the file, right-click, and then click Properties

Display the Start menu

Ctrl + Esc

Create a shortcut on your desktop to your favorite file/folder

Drag the file/folder icon to your desktop

Scroll between open items

Alt + Tab, then hold down Alt while clicking Tab to reach the desired file or program

Thursday, November 19, 2009

check out the PDC 09 videos

check out the PDC 09 videos here

Managed Extensibility Framework

The Managed Extensibility Framework (MEF) has been getting a lot of interest lately and it’s something that’s out on CodePlex and it’s also part of .NET Framework 4.0.

It’s also part of Silverlight 4.

The name’s a good one – it’s a framework for building an application that is made up of a bunch of loosely coupled components with a lot of flexibility around component discovery, registration, lookup and lifetime management. If I had to sum it up in my own words I’d say something like;

MEF composes an application by extensibly discovering a set of components which offer exported functionality and ( possibly ) rely on imported functionality. The link between the two is a simple string name ( a MEF “contract name” ) which is usually represented by a .NET type name and MEF has the capability to plug things together where it finds ( possibly further constrained ) matches.

Read full post of mike here

How to check if Silverlight Running out of browser or in the browser ?

As Silverlight increases its Out of Browser features it will become more important to detect if the application is running in or out of the browser.  This is the check:

if (Application.Current.IsRunningOutOfBrowser)
{
// Out of Browser

}
else

{
// in the browser

}

Silverlight 4 Beta is Now Available

Yesterday, at the PDC in Los Angeles, Scott Guthrie announced the availability of Silverlight 4 beta, just four months after bringing Silverlight 3 to market. With the help of several customers we showcased the new features that will enable developers to create the highest quality media and RIA applications for the Web and desktop. These powerful new features offer developers significant benefits in rapidly creating rich software experiences, and include:

· Enhancements to Silverlight out-of-browser capabilities which enable high quality application experiences on the desktop;

· Advancements in business application development, including access to other Microsoft products like SharePoint 2010, Office, and Internet Information Services (IIS);

· The most amazing HD-quality video experiences on the Web with native multicast and offline DRM support.

In addition, our list of customers and HD streaming events continues to grow, with 45 percent of Internet-connected devices worldwide using Silverlight. Today we highlighted the diverse ways Silverlight is being used to power the applications we use every day such as, Portland, OR startup SnapFlow, who demonstrated their new workflow-making platform. We’re also looking forward to helping NBC broadcast the 2010 Vancouver Winter Games in HD-quality video with Silverlight and IIS Smooth Streaming on NBCOlympics.com beginning February 12, 2010.

Drop by the PDC Virtual Pressroom to view Scott Guthrie’s keynote and to find out more information about Silverlight 4 beta. To download Silverlight 4 beta visit the Silverlight.net community site.

Monday, November 9, 2009

NOW, here is a true INDIAN! I was moved to read this young man’s story.

Have you ever seen Mahatma Gandhi??

If not, come and visit Thennur village near Trichy. You cannot see Mahatma Gandhi there. But you can see a ‘Young’ Gandhi there. I got a chance to go there when we went to our friend Thilaga’s marriage. Here is a man who was earning Rs 2 lakhs per month 5years ago in the US. One of his ambitions, from the time he was studying in school, is to serve his village. Hence, after earning some money for his parents, he resigned his job in the US and came to his village to start an NGO in order to support the village. He is just 36 years old now which means he resigned his job when he was 31! He is also called as ‘Ilam Gandhi’ (Young Gandhi).

So, what did he do after resigning his job?? He invested Rs 40 lakhs in Thennur to build a community health center and an informal learning center. Out of the Rs 40 lakhs which he spent, Rs 31 lakhs came out of his own pocket. He started an NGO called ‘Payir’ to help this village

Have a look at his PAYIR’s building’s below:

clip_image001

The community health center:

clip_image002

clip_image003

Informal learning center

clip_image004

Now, he has appointed 5 people who are locals and who function as his staff. They teach proper English to the schools available in their locality.

Local staffs working in Payir

clip_image005

And that is not all! He has created a small IT company within that village. This company has 4 employees as of now, who are all graduates from this village. They have a US client and are currently working on a $2500 project. This IT company is in the middle of a Coconut farm.

Have a look at their IT company below:

The IT company in the middle of a farm

clip_image006

Inside the company

clip_image007

Fan inside the IT company

clip_image008

While working in the US, he used to deposit a little money for his parents as one of his mother’s wishes was to build a house for themselves. With his savings, his parents now live in a big house at Srirangam. See the picture below:

clip_image009

But, that’s not the case with him. He lives in a small hut in that village itself.

Have a look at his room below:

clip_image010

I asked him, how he is able to live without any earnings? His reply was as follows:

“Payir trust provides me with daily food. My trustees have agreed on this. I have built a hut for myself using my past earnings. So shelter is not a problem. I have 3sets of shirts and Vesti(Dhoti) which I can use for the next 2 years. My friends will get me a few dresses once or twice in a year. What more do I need in my life??”.

Have a look at the slipper of the great man who was earning 2Lakhs a month in US:

clip_image011

When I asked, how he will manage in his old age, if he gets any disease, he coolly replied that he will go to a Govt. hospital where everything is free of cost.

My question is: How many of us will dare to act like Senthil ? Many of us have so many dreams in life like becoming a music director, to become a cricketer, to do MBA, go to the Himalayas, help the schools where we studied, to become a district collector etc etc.. But we all lose our dreams just to earn money and want to reach a position which we call it as ‘Status’. We determine our path by seeing what others are doing. We select our needs based on what others have. We select a course to study based on the job availability and its salary rather than our interest for the subject.

Every one forgets that we have only one life to achieve our dream. Many of us chase what we do not want actually. If you still have some of your dreams unfulfilled, remember that you are the reason behind it. Start now and chase your dreams!

Senthil had a dream and he started executing it now! Believe me or not. Senthil started dreaming about Payir organization during his 11th std!

Senthil - The real hero!

clip_image012

Coming to the social aspect of Senthil, how many of us will leave all that we have earned and work for the benefit of others? Have we ever dreamt of doing what Senthil has done?

While returning from Thennur, only one thing was running on my mind. If everyone of us did atleast 0.1% of what Senthil has done, our India will be much better than any other country in this world!!

If many of us continue to focus on personal growth without worrying about our nation, in future, there will be many more Senthil’s around us who would have sacrificed their personal life for the welfare of this country.

Thennur is not just another village in our India map. It is a start of a new beginning for India. Thennur is a proof of the change that youth can bring in our country.

Monday, October 12, 2009

How To Export Data in a DataGrid on an ASP . NET WebForm to Microsoft Excel

  • Start Visual Studio .NET. On the File menu, point to New, and then click Project.
  • In the Project Types pane, click Visual Basic Projects. Under Templates, click ASP.NET Web Application. Name the application ExcelExport and then click OK.
    WebForm1 appears in Design view for you.
  • In Solution Explorer, right-click WebForm1.aspx and then click Rename. Change the name of the file to Bottom.aspx.
  • On the View menu, click HTML Source to add the following DataGrid between the < form > and < / form > tags:

    <asp:datagrid id="DataGrid1" runat="server" GridLines="Vertical" CellPadding="3" BackColor="White" BorderColor="#999999" BorderWidth="1px" BorderStyle="None" Width="100%" Height="100%" Font-Size="X-Small" Font-Names="Verdana"> <SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#008A8C"></SelectedItemStyle> <AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle> <ItemStyle BorderWidth="2px" ForeColor="Black" BorderStyle="Solid" BorderColor="Black" BackColor="#EEEEEE"></ItemStyle> <HeaderStyle Font-Bold="True" HorizontalAlign="Center" BorderWidth="2px" ForeColor="White" BorderStyle="Solid" BorderColor="Black" BackColor="#000084"></HeaderStyle> <FooterStyle ForeColor="Black" BackColor="#CCCCCC"></FooterStyle> <PagerStyle HorizontalAlign="Center" ForeColor="Black" BackColor="#999999" Mode="NumericPages"></PagerStyle> </asp:datagrid>

  • On the View menu, click Design to return to design view.
    The DataGrid appears on the WebForm.
  • On the View menu, click Code to display the code behind the Web Form. Add the following code to the Page_Load event handler:

    Note You must change User ID <username> and password=<strong password> to the correct values before you run this code. Make sure that the user account has the correct permissions to perform this operation on the database.


    ' Create a connection and open it. Dim objConn As New System.Data.SqlClient.SqlConnection("User ID=<username>;Password=<strong password>;Initial Catalog=Northwind;Data Source=SQLServer;") objConn.Open() Dim strSQL As String Dim objDataset As New DataSet() Dim objAdapter As New System.Data.SqlClient.SqlDataAdapter() ' Get all the customers from the USA. strSQL = "Select * from customers where country='USA'" objAdapter.SelectCommand = New System.Data.SqlClient.SqlCommand(strSQL, objConn) ' Fill the dataset. objAdapter.Fill(objDataset) ' Create a new view. Dim oView As New DataView(objDataset.Tables(0)) ' Set up the data grid and bind the data. DataGrid1.DataSource = oView DataGrid1.DataBind() ' Verify if the page is to be displayed in Excel. If Request.QueryString("bExcel") = "1" Then ' Set the content type to Excel. Response.ContentType = "application/vnd.ms-excel" ' Remove the charset from the Content-Type header. Response.Charset = "" ' Turn off the view state. Me.EnableViewState = False
    Dim tw As New System.IO.StringWriter() Dim hw As New System.Web.UI.HtmlTextWriter(tw) ' Get the HTML for the control. DataGrid1.RenderControl(hw) ' Write the HTML back to the browser. Response.Write(tw.ToString()) ' End the response. Response.End()
    End If




  • NOTE: Replace SQLServer in the code with the name of your SQL Server. If you do not have access to a SQL Server that contains the Northwind sample database, modify the connection string to use the Microsoft Access 2002 sample Northwind database:

    provider=microsoft.jet.oledb.4.0; data source=C:\Program Files\Microsoft Office\Office10\Samples\Northwind.mdb

    If you select this method, modify the aforementioned code to use the OleDbClient namespace rather than the SqlClient namespace.

  • On the Project menu, click Add HTML Page. Name the page Top.htm and then click Open.
    Top.htm appears in Design view.
  • On the View menu, click HTML Source. Replace the contents of the HTML source window with the following code:

    <html> <script language="vbscript"> Sub Button1_onclick Select Case Select1.selectedIndex Case 0 ' Use Automation. Dim sHTML sHTML = window.parent.frames("bottom").document.forms(0).children("DataGrid1").outerhtml Dim oXL, oBook Set oXL = CreateObject("Excel.Application") Set oBook = oXL.Workbooks.Add oBook.HTMLProject.HTMLProjectItems("Sheet1").Text = sHTML oBook.HTMLProject.RefreshDocument oXL.Visible = true oXL.UserControl = true Case 1 ' Use MIME Type (In a New Window). window.open("bottom.aspx?bExcel=1") Case 2 ' Use MIME Type (In the Frame). window.parent.frames("bottom").navigate "bottom.aspx?bExcel=1" End Select End Sub </script> <body> Export to Excel Using: <SELECT id="Select1" size="1" name="Select1"> <OPTION value="0" selected>Automation</OPTION> <OPTION value="1">MIME Type (In a New Window)</OPTION> <OPTION value="2">MIME Type (In the Frame)</OPTION> </SELECT> <INPUT id="Button1" type="button" value="Go!" name="Button1"> </body> </html>

  • On the Project menu, click Add HTML Page. Name the page Frameset.htm and then click Open.
    Frameset.htm opens in Design view.
  • On the View menu, click HTML Source. Replace the contents of the HTML source window with the following code:

    <html> <frameset rows="10%,90%"> <frame noresize="0" scrolling="no" name="top" src="top.htm"> <frame noresize="0" scrolling="yes" name="bottom" src="bottom.aspx"> </frameset> </html>

  • In Solution Explorer, right-click Frameset.htm and then click Set As Start Page.
  • On the Build menu, click Build Solution.
  • On the Debug menu, click Start Without Debugging to run the application.
    After the frameset opens in the Web browser, the DataGrid in the bottom frame displays the data from the Northwind database.
  • In the drop-down list, click Automation, and then click Go.
    The DataGrid contents are displayed outside the browser in the Microsoft Excel application window.
  • In the drop-down list, click MIME Type (In a New Window), and then click Go.
    The DataGrid contents are displayed in Excel hosted in a new Web browser window.
    NOTE: If you receive a prompt to open or save the Excel file, click Open.
  • In the drop-down list, click MIME Type (In the Frame) and then click Go.
    The DataGrid contents are displayed in the bottom frame of the frameset in Excel hosted in the Web browser.
    NOTE: If you receive a prompt to open or save the Excel file, click Open.

    enjoy……………………..

  •