Sunday, February 24, 2008

Passing Values between Web Pages (Beginner)

During a coffee break at work, I was explaining my friend how I had used a Wizard control in my Web App for the User registration process and had saved myself from headaches involving passing data between pages, storing user selection of choices in each page etc. My friend was pretty impressed with what the Wizard control could achieve and commended Scott & his team at Redmond for making things simple for programmers. "Developing Web Apps is pretty challenging compared to a Windows Application. And that is the sex appeal of developing Web Apps.."

True!! I started to wonder about the difference in approach between a Web App and a Windows Application. In case of a windows application passing data between 2 forms is a piece of cake. But how do I pass values between web pages? I was sure that it wasn't something very complex, but I realized that it was something I did not know. So I decided to try that and did so in a matter of minutes. Thanks to the documentation and example at msdn! This is what I did.

1. I created a new website with 2 pages Default.aspx and Default2.aspx

2. In Default.aspx I added a Textbox and a button.

3. In Default2.aspx I added a Label. My Objective was to display text entered in the text box in the label on click of the button.

4. I set the PostbackUrl of button to Default2.aspx

ID="Button1" runat="server" Text="Button" PostBackUrl="~/Default2.aspx"


5. Next I write the following code in the page load of Default2.aspx

if (Page.PreviousPage != null)
{
TextBox SourceTextBox = (TextBox)Page.PreviousPage.FindControl("TextBox1");

if (SourceTextBox != null)
{
Label1.Text = SourceTextBox.Text;
}
}


6. And that's it! The value of the text box is passed onto the Label on the second page.

This is one of the many ways of passing data between pages. I will explore and post about them in the coming weeks.

Till Then Happy Programming !!

Tuesday, February 19, 2008

Techsassy Now also available at Wordpress!!

In my last post, I said that I would be posting a few tips over the weekend. But 3 weekends have passed since my last post and nothing has come!! Well the weekends after my last post have been involved in learning new things about ASP.NET, catching up with my cousins and whats been happening back home. And yeah on one of the weekends there was a power surge which resulted in my UPS blasting and smoking off. I have given it for repair and hope it will be functional by next weekend. Also we have been facing a few electrical problems( meaning no electricity ) since last week which was fixed just today. So I guess you pretty much get the idea WHY there have been no posts for quite some time.

Anyway, for the past three weeks I have been trying to build a sort of registration page using the WIZARD control of ASP.NET 2.0. This has been quite challenging. I am on the verge of finishing it off ( hopefully I will do that by tomorrow). I will then be posting an article on CodeProject about how I used the wizard control to achieve my objectives. Of course, you will find that here as well.

Over the past few weeks, I have also started using the asp.net forums to post queries and answer whatever I can. Using the forums, I definitely feel a part of the ASP.NET developer community. The community is very active and I got replies to my queries within the hour.

Which reminds of one of the headlines in tech news for today. Microsoft, is about announce a program wherein it is going to give software like Visual Studio Professional Edition, Windows Server, SQL Server Developer etc. to student across eight countries for free.More about that here Definitely this is good news but India is not in that list. This to me is a defining moment. This is what Open Source and Free Software have done.

And before I end, I have made a copy of this blog at wordpress. It is http://techsassy.wordpress.com. Why wordpress? Till not it is now completely blocked at my office. Dont know what is the company achieving by blocking blogger and other blogs.

Anyway, hopefully my next post will be helpful for developers and should be up soon. Till then, Happy Programming!!