Posted by: Dharmesh Shah | April 23, 2010

What is WPF and use of XAML(An Integral Part Of WPF):-

• It is used to develop GUI for windows application as well as web application.

• It supports 3D rendering, Animation and Multimedia features within a single API.

• WPF applications can also be developed using XAML which is a markup language.

• We can develop applications with 3D rendering, Animation and Multimedia features just using a single API and less effort using WPF.

WPF provides us the capability to design windows applications like an ASP.NET application using markup language. Microsoft called this as XAML(Extended Application Markup Language). XAML provides a separation of coding from designing. So you can develop your application using the toolbox and properties window like the general windows application or in a different form like web applications using markup language.

XAML is capable to provide all the simple UI elements (such as labels, textboxes, etc.) to complex functionality (animation, graphics rendering and multimedia support). If you want to animate a button with a picture on it you only need a few line of XAML code. WPF elements can also be customized using styles and templates, minimizing your efforts. There are also a lot of tools to generate XAML code for you. You have to just define the UI in a drag and drop manner. You can also apply rendering effects and animations to these UI using a simple IDE. Then the IDE will give you the XAML code to be used in your application.

Posted by: Dharmesh Shah | April 19, 2010

How to calculate age in C#..?

public static int CalculateAge(DateTime birthDate)
// cache the current time
DateTime now = DateTime.Today; // today is fine, don’t need the timestamp from now
// get the difference in years
int years = now.Year – birthDate.Year;
// subtract another year if we’re before the
// birth day in the current year
if (now.Month < birthDate.Month || (now.Month == birthDate.Month && now.Day < birthDate.Day))
– – years;
return years;

Posted by: Dharmesh Shah | April 8, 2010

How to use adrotator control in ASP.Net?

An adrotator control is available in ASP.Net to ease the task of rotating the advertisement images in a web form. This control enables you to display a different image whenever you refresh the page. This adrotator control takes the information about the images that are to be displayed from an XML file which also have many other elements in it that are used by this control. First let us have a look at a sample advertisement file that is used by the adrotator control in ASP.Net.

Let us assume that the advertisement XML file is named as advt.xml. This file might look like,


<AlternateText>Site1 Main</AlternateText>

<AlternateText>Site2 Main Page</AlternateText>


The XML file that is used for advertisements would have the root element as the element. This may have many AD child elements. The elements ImageUrl,NavigateUrl,AlternateText,Impressions and Keyword are found in the AD element. These elements identify the properties of the image that is displayed using the adrotator control.

The ImageUrl element specifies the path to the image that is displayed using the AdRotator control. Once a user clicks the image that is displayed the user is taken to the URL specified in the NavigateUrl element. The AlternateText element holds the text that is displayed when the image is not loaded. The text in this element is also used as a ToolTip in some of the browsers. The element Impressions has a number as a value. This number indicates how often the image is displayed with respect to other images. The more the value of the number in this element, the more is the frequency of the image that is displayed. The sum of all the impressions in the advertisement file should not exceed 2,047,999,999. Otherwise the AdRotator will throw an runtime exception. The Keyword element is used to give the category of the advertisement.

You can just drag and drop a AdRotator control in the webform and set its attributes if you are using Visual Studio .Net. The code that is generated for the AdRotator control might be something as given below:

<asp:AdRotator id="AdRotator1" Target="_self"
AdvertisementFile="advt.xml" runat="server"/>

In the above code in the HTML file you could see that the AdvertisementFile attribute of the AdRotator control has the xml file “advt.xml”. The other attributes are ‘id’ and ‘Target’. During runtime the AdRotator control uses the controls like asp:HyperLink and asp:Image to display the image in the web form page. The size of the image that is displayed is limited by the size of the AdRotator control that is found in the page. So, if you want to display larger images you need to adjust the size of the AdRotator control during design time itself.

It is possible to modify the values of the ImageUrl,NavigateUrl and AlternateText programmatically. For this you can use the AdCreated event. Thus by using the AdCreated event the rendering of the AdRotator control can be controlled.

Thus the AdRotator control is an easy way to display and rotate advertisements and also to give preference to some advertisements by using the Impressions element of the advertisement xml file….

Posted by: Dharmesh Shah | April 6, 2010

EnableViewState is not working for Text Box.!! ?

Before some days I was just exploring that How EnableviewState works. I noticed one thing that EnableViewState is not working with the textbox. I tried this example

I put a text box with EnableViewState= “false” and a button on the page.

I entered some value in the textbox and When I clicked on the button, the page got refreshed but the text box was maintaining its value.
It was a bit weird thing for me.

After hours of hard work, I came to know this.”Textboxes do not use ViewState to maintain their values across postbacks.These controls simply post their values as normal to the server and then the server simply takes that value and makes it be the default value of the new control generated for the postback. You can see this if you view the source code of the page after the initial form submission, the textbox will have a ‘value’ attribute set to the data entered into the textbox when it was submitted.”

Posted by: Dharmesh Shah | April 6, 2010

How to maintain Password mode Textbox value?

Here i want to describe that how to maintain password mode Textbox value during Postback in form..

protected void Page_Load(object sender, EventArgs e)
ViewState[“_Pass”] = TxtPassword.Text;
protected void Page_PreRender(object sender, EventArgs e)
TxtPassword.Attributes.Add(“value”, ViewState[“_Pass”].ToString());


Older Posts »