August 2008

Post navigation

Some developers are still want to use cross page post backs that we used it in the classic version of ASP. For example: you may want to create a page that contains a form and add them to your database in another page like ASP classic.

In this post I want to show how to do such a thing in ASP.NET and how you can make it easier in ASP.NET 3.5.

Imagine that I have a Default/ file that shows a form and users can enter their name and company name; and also I have another page named DataTransfer/ that shows user’s information in some labels.

Here is my Default/ page:

<%@ Page Language="C#"

AutoEventWireup="true"

CodeFile="Default/.cs" Inherits="_Default" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title></title>

</head>

<body>

<formid="form1"runat="server">

<divstyle="text-align: center;">

Name:<br/>

<asp:TextBoxrunat="server"ID="nameTextBox"></asp:TextBox><br/>

Company name:<br/>

<asp:TextBoxrunat="server"ID="companyTextBox"></asp:TextBox><br/>

<asp:Buttonrunat="server"ID="submitButton"

Text="Save"

PostBackUrl="DataTransfer/"/>

</div>

</form>

</body>

</html>

As you can see, I have two textboxes named "nameTextBox", "companyTextBox" and also a button named "submitButton" that are normal and there is nothing unusual in it. The interesting part in the PostBackUrl of my button that links this page to our second page.

There is nothing to do more in the first page, so lets take a look at our second page "DataTransfer/":

Very simple, just two labels in order to show the user’s information. I have to write some code in the code-behind section in order to bind information to labels. Here is my code-behind of my DataTransfer/:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

publicpartialclass DataTransfer : System.Web.UI.Page

{

protectedvoid Page_Load(object sender, EventArgs e)

{

// Create an instance of our previous page's controls that we want to get.

TextBox name = null;

TextBox company = null;

// Fill variables with the values in the previous page using FindControl method of Previous Page property.

name = (TextBox)this.PreviousPage.FindControl("nameTextBox");

company = (TextBox)this.PreviousPage.FindControl("companyTextBox");

// Bind lables using values in textboxes.

nameLabel.Text = name.Text;

companyLabel.Text = company.Text;

}

}

In the code above I used PreviousePage property available in every ASP.NET page and FindControl method of that property. With FindControl you can get the object you want by it’s ID from your previous page. But because the information returns from FindControl are objects and no specific types, you must cast it as I did.

If you launch your application now, you will see you can gather the information from first page and show them in the second page.

Now let’s change it a little bit by add a new directive to our second page. This directive name PreviousPageType and it’s new with ASP.NET 3.5 and let you specify your previous page path. So you can have all public or internal (Friend in VB) classes, methods, properties or any other objects in your second page. This is my second page after a little changes:

You know, because I’m always trying to be organized :D, I want to create two properties in my first page that holds values in textboxes:

publicstring Name

{

get { return nameTextBox.Text; }

}

publicstring CompanyName

{

get { return companyTextBox.Text; }

}

Now you can get values of textboxes in Default/ page much easier. It means that Visual Studio can identify our first page objects and you can use code hints in order to access your objects in the second page as shown in the picture below:

And our second page’s code-behind will change to the following:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

publicpartialclass DataTransfer : System.Web.UI.Page

{

protectedvoid Page_Load(object sender, EventArgs e)

{

// Fill variables with the values in the previous page using properties.

nameLabel.Text = PreviousPage.Name;

companyLabel.Text = PreviousPage.CompanyName;

}

}

Now you know that with the PreviousPageType new directive in ASP.NET 3.5, it’s much easier to access you object in a page from another page.

Today Microsoft released the latest version of Internet Explorer (8 beta 2) and it’s now available for download. But before download, lets take a look at some of new features in this release of Internet Explorer:

InPrivate Browsing:

Keep Internet Explorer 8 from adding any sites you visit to Browsing History with InPrivate Browsing. Now you can shop for that special gift with confidence knowing your family won’t accidentally find out.

Search suggestions:

Search smarter with detailed suggestions from your favorite search providers and browsing history. See visual previews and get suggested content topics while you type in the enhanced Instant Search Box.

Compatibility View:

Internet Explorer 8’s built-in Compatibility View button enables you to display websites that were designed for older browsers. Simply press the Compatibility View button if you see display problems on a website like misaligned text, images, or text boxes. It’s located next to the Refresh button on the Address Bar.

SmartScreen Filter:

New security features help to protect you against deceptive and malicious websites which can compromise your data, privacy, and identity.

Web Slices:

Keep up with changes to the sites you care about most. Add a Web Slice and you won’t have to go back to the same website again and again for updates on news, stock quotes, online auctions, weather, or even sports scores.

Accelerators:

Accelerators let you complete your everyday browsing activities more quickly and even discover new services. Start mapping, translating, emailing, and more in just a few mouse clicks.

Maybe some of you want to ask me: OK. SQL Server 2008 is the latest version of SQL Server but what’s new in it?

Today I want to introduce you to some of top features available in SQL Server 2008. This is an screen shot of a SQL Server 2008 query. You can see some of new features you can use in the latest version of SQL Server:

As you saw, there are some amazing features has been added to the new version. Here is a list of most interesting features that implemented in the latest version of SQL Server:

Increase the precision of storing and managing DATE and TIME information.

I don’t know exactly why I’m feeling tired these weeks. I planned to do some personal works but unfortunately I couldn’t. Today I decided to write a new post and talk about what a person should do on his/her weekends, in my opinion.

The first thing you have to consider about is try not to do the things you’re doing on weekdays; For example I’m a developer and I’m developing about 12-15 hours a day, I have to quit developing on my weekends. You know in my opinion it will help you to have more creativity in the following week.

So what can I do on my weekends?

In my opinion it’s better to do the following things on our weekends:

· Reading books (Read books you think they can help you out in your future).

· Going out with friends and family.

· Watch some movies (Action movies recommended).

· Organize your works (You can also plan for the following week on weekends). If you are a organize person you can fill out you calendar on your weekends.

· Clean up you room or home (If you have any).

· Check out some ways of succeeds.

· …

It’s very important to not to think about your current or following work on weekends because it will give you stresses and you cannot enjoy your weekend.

in the code above I created an XML file exactly like our previous exmple and the result will be equal.

Lets take a look at this code snippet; In Visual Basic when you declare a variable as XElement, you can write your XML content exactly like the syntax you're using in an XML file. It means that you can use XML tags (<configs></configs>) straight in your code.

As I said in my previous posts, I like VB more than C# and I thing VB is much powerful than C# at least in this part :).