Showing posts with label Web Application. Show all posts
Showing posts with label Web Application. Show all posts

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 !!

Wednesday, December 19, 2007

Changing CSS having no effect!

In the week just gone by, I received a web app from one of my colleagues who was on medical leave. This was supposed to be a prototype of what I will be developing in the days to come. However, there were many issues with the UI of the site. The color scheme though looked good did not match with the logo of the company and had to be changed.

It took me some time to realize that the CSS file being used was one within the App_Themes folder and not the one outside. I had been making changes to the wrong file, hence the changes I was making were not reflecting. But hang on!! Now I was making changes to the correct file but still I could not see the changes reflecting in the front end. I double checked and was stumped. Just moments ago the changes made to the CSS were reflecting in the UI. What could be the possible reason now?

Somehow I had the feeling that I should refresh the page once(probably because of my experience with Service Desk Customization) and Bingo!!

Now I again I made some changes mainly changing the logo, but again it wasn't reflecting. I refreshed. Nothing!! Now what could be the reason? Thankfully I had a backup of the original CSS file. I compared that with the modified one. I realized what was happening. To work faster I was using the build style option in Visual Web Developer. When you use this a Window opens where you can visually set the CSS properties. I was using this to set the background image to the one I had created. The location of this image was "App_Themes/Theme1/Images/Image1.gif". So what was happening was the in the CSS the same url for the image was getting stored. But as my CSS file was already located at "App_Themes/Theme1/" the correct url for the image should have been "/Images/Image1.gif". I changed the Url and Voila!!

As I had posted earlier, Microsoft is always trying to simplify things by allowing you to code Visually. But this Visual coding style has pitfalls and is a sure source of many bugs in applications. My advice to all is "Be Extra Careful when writing code Visually!"

Cheers!!