Cross-Page post backs using ASP.NET 3.5

clock August 30, 2008 02:06 by author Mohammad Mahdi Ramezanpour

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.aspx file that shows a form and users can enter their name and company name; and also I have another page named DataTransfer.aspx that shows user's information in some labels.

Here is my Default.aspx page:

<%@ Page Language="C#" 
AutoEventWireup="true" 
CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div style="text-align: center;">
        Name:<br />
        <asp:TextBox runat="server" ID="nameTextBox"></asp:TextBox><br />
        Company name:<br />
        <asp:TextBox runat="server" ID="companyTextBox"></asp:TextBox><br />
        <asp:Button runat="server" ID="submitButton"
         Text="Save" 
         PostBackUrl="DataTransfer.aspx" />
    </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.aspx":

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataTransfer.aspx.cs" Inherits="DataTransfer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <h3>User's information</h3>
    <div>
        Name : 
        <asp:Label runat="server" ID="nameLabel"></asp:Label><br />
        Company : 
        <asp:Label runat="server" ID="companyLabel"></asp:Label>
    </div>
    </form>
</body>
</html>

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.aspx:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class DataTransfer : System.Web.UI.Page
{
    protected void 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:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataTransfer.aspx.cs" Inherits="DataTransfer" %>
<%@ PreviousPageType VirtualPath="~/Default.aspx" %>
...

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:

    public string Name
    {
        get { return nameTextBox.Text; }
    }
 
    public string CompanyName
    {
        get { return companyTextBox.Text; }
    }

Now you can get values of textboxes in Default.aspx 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:

ASPNET35 Previous Page Inteligency

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;
 
public partial class DataTransfer : System.Web.UI.Page
{
    protected void 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.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Internet Explorer 8 beta 2 released

clock August 29, 2008 00:04 by author Mohammad Mahdi Ramezanpour

Internet Explorer 8 beta 2

 

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.

 

For more information about features and download it check out Internet Explorer 8 home page : http://www.microsoft.com/ie8

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Four hours free ASP.NET 3.5 training

clock August 28, 2008 01:00 by author Mohammad Mahdi Ramezanpour

ASP_net_logo

This is a special news to some of you who want to start developing ASP.NET. APPDEV, released 4 hours of free ASP.NET training and it's now available for download.

The best part is that these courses are available in both VB.NET and C#. So it doesn't matter which programming language you're using.

Download training courses by click the following link:

http://www.appdev.com/promo.asp?page=SN00040

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


The most interesting features in SQL Server 2008

clock August 25, 2008 23:11 by author Mohammad Mahdi Ramezanpour

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:

scrn-SQL08

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.

  • Store semi-structured and sparsely populated sets of data efficiently, using Sparse Columns.

  • New fully integrated Full-Text Indexes enable high-performance, scalable, and manageable Full-Text Indexing.

  • Create large User-Defined Types and User-Defined Aggregates greater than 8 KB.

  • Pass large amounts of data easily to functions or procedures using new Table-Value Parameters.

  • Perform multiple operations efficiently with the new MERGE command.

  • Model hierarchical data, such as org charts, or files and folders, using the new HierarchyID data type.

  • Build powerful location-aware applications, using SQL Server’s new standards-compliant spatial data types and spatial indexing capabilities.

  • Manage files and documents efficiently with full SQL Server security and transaction support, using the powerful new FILESTREAM data type.

  • Easily identify dependencies across objects and databases, using New Dependency Management.

  • Experience faster queries and reporting with Grouping Sets through powerful ANSI standards-compliant extensions to the GROUP BY clause.

  • Experience efficient, high-performance data access, using new Filtered Indexes for subsets of data.

  • Currently rated 1.3 by 3 people

    • Currently 1.333333/5 Stars.
    • 1
    • 2
    • 3
    • 4
    • 5


    What is APML?

    clock August 25, 2008 01:53 by author Mohammad Mahdi Ramezanpour

    I just implemented APML in my website two days ago. Some of my friends ask me about it and decided to upload this post in order to talk about it.

    What is APML in one sentence?

    Attention Profiling Markup Language (APML) is an open standard that encapsulates a summary of your interests (across multiple profiles) in a simple, portable way.

    The structure of APML is something like this:

    APML

    here is an example of an APML file that can be found at: http://www.ramezanpour.net/apml.axd

    <?xml version="1.0" encoding="utf-8"?>
    
    <APML>
    
      <Head>
    
        <Title>APML data for Mohammad Mahdi Ramezanpour's website - A place you can improve your programming knowledge</Title>
    
        <Generator>Ramezanpour.net</Generator>
    
        <UserEmail />
    
        <DateCreated>8/25/2008 1:37:34 AM</DateCreated>
    
      </Head>
    
      <Body defaultProfile="tags">
    
        <Profile name="tags">
    
          <ImplicitData>
    
            <Concepts>
    
              <Concept key="form authectication" value="1" from="http://www.ramezanpour.net/" updated="7/8/2008 10:49:51 PM" />
    
              <Concept key="player" value="1" from="http://www.ramezanpour.net/" updated="7/26/2008 2:20:48 PM" />
    
              <Concept key="authentication" value="1" from="http://www.ramezanpour.net/" updated="7/8/2008 10:49:51 PM" />
    
              <Concept key=".net authentications" value="1" from="http://www.ramezanpour.net/" updated="7/8/2008 10:49:51 PM" />
    
              <Concept key="forms" value="1" from="http://www.ramezanpour.net/" updated="7/8/2008 10:49:51 PM" />
    
              <Concept key=".net framework" value="1" from="http://www.ramezanpour.net/" updated="7/31/2008 1:38:02 AM" />
    
              <Concept key="sql server 2008" value="1" from="http://www.ramezanpour.net/" updated="8/12/2008 6:53:56 PM" />
    
              <Concept key="linq" value="1" from="http://www.ramezanpour.net/" updated="7/31/2008 1:38:02 AM" />
    
              <Concept key="meizu" value="1" from="http://www.ramezanpour.net/" updated="7/26/2008 2:20:48 PM" />
    
              <Concept key="mp3 player" value="1" from="http://www.ramezanpour.net/" updated="7/26/2008 2:20:48 PM" />
    
            </Concepts>
    
          </ImplicitData>
    
        </Profile>
    
        <Profile name="links">
    
          <ExplicitData>
    
            <Concepts />
    
          </ExplicitData>
    
        </Profile>
    
      </Body>
    
    </APML>
    

    From here, powered by: Elias Bizannes 

    APML - the specification
    APML stands for Attention Profile Markup Language. It’s an attention economy concept, based on the XML technical standard. I am going to assume you don’t know what attention means, nor what XML is, so here is a quick explanation to get you on board.

    Attention
    There is this concept floating around on the web about the attention economy. It means as a consumer, you consume web services - e-mail, rss readers, social networking sites - and you generate value through your attention. For example, if I am on a Myspace band page for Sneaky Sound System, I am giving attention to that band. Newscorp (the company that owns MySpace) is capturing that implicit data about me (ie, it knows I like Electro/Pop/House music). By giving my attention, Newscorp has collected information about me. Implicit data are things you give away about yourself without saying it, like how people can determine what type of person you are purely off the clothes you wear. It’s like explicit data - information you give up about yourself (like your gender when you signed up to MySpace).

    XML
    XML is one of the core standards on the web. The web pages you access, are probably using a form of XML to provide the content to you (xHTML). If you use an RSS reader, it pulls a version of XML to deliver that content to you. I am not going to get into a discussion about XML because there are plenty of other places that can do that. However I just want to make sure you understand, that XML is a very flexible way of structuring data. Think of it like a street directory. It’s useless if you have a map with no street names if you are trying to find a house. But by having a map with the street names, it suddenly becomes a lot more useful because you can make sense of the houses (the content). It’s a way of describing a piece of content.

    APML - the specification
    So all APML is, is a way of converting your attention into a structured format. The way APML does this, is that it stores your implicit and explicit data - and scores it. Lost? Keep reading.

    Continuing with my example about Sneaky Sound System. If MySpace supported APML, they would identify that I like pop music. But just because someone gives attention to something, that doesn’t mean they really like it; the thing about implicit data is that companies are guessing because you haven’t actually said it. So MySpace might say I like pop music but with a score of 0.2 or 20% positive - meaning they’re not too confident. Now lets say directly after that, I go onto the Britney Spears music space. Okay, there’s no doubting now: I definitely do like pop music. So my score against “pop” is now 0.5 (50%). And if I visited the Christina Aguilera page: forget about it - my APML rank just blew to 1.0! (Note that the scoring system is a percentage, with a range from -1.0 to +1.0 or -100% to +100%).

    APML ranks things,  but the concepts are not just things: it will also rank authors. In the case of Marjolein Hoekstra, who wrote that post I mention in my intro, because I read other things from her it means I have a high regard for her writing. Therefore, my APML file gives her a high score. On the other hand, I have an allergic reaction whenever I read something from Valleywag because they have cooties. So Marjolein’s rank would be 1.0 but Valleywag’s -1.0.

    Aside from the ranking of concepts (which is the core of what APML is), there are other things in an APML file that might confuse you when reviewing the spec. “From” means ‘from the place you gave your attention’. So with the Sneaky Sound System concept, it would be ‘from: MySpace’. It’s simply describing the name of the application that added the implicit node. Another thing you may notice in an APML file is that you can create “profiles”. For example, the concepts about me in my “work” profile is not something I want to mix with my “personal” profile. This allows you to segment the ranked concepts in your APML into different groups, allowing applications access to only a particilar profile.

    Another thing to take note of is ‘implicit’ and ‘explicit’ which I touched on above - implicit being things you give attention to (ie, the clothes you wear - people guess because of what you wear, you are a certain personality type); explicit being things you gave away (the words you said - when you say “I’m a moron” it’s quite obvious, you are). APML categorises concepts based on whether you explicitly said it, or it was implicitly determined by an application.

    Okay, big whoop - why can an APML do for me?
    In my eyes, there are five main benefits of APML: filtering, accountability, privacy, shared data, and you being boss.

    1) Filtering
    If a company supports APML, they are using a smart standard that other companies use to profile you. By ranking concepts and authors for example, they can use your APML file in the future to filter things that might interest you. As I have such a high ranking for Marjolein, when Bloglines implements APML, they will be able to use this information to start prioritising content in my RSS reader. Meaning, of the 1000 items in my bloglines reader, all the blog postings from her will have more emphasis for me to read whilst all the ones about Valleywag will sit at the bottom (with last nights trash).

    2) Accountability
    If a company is collecting implicit data about me and trying to profile me, I would like to see that infomation thank you very much. It’s a bit like me wearing a pink shirt at a party. You meet me at a party, and think “Pink - the dude must be gay”. Now I am actually as straight as a doornail, and wearing that pink shirt is me trying to be trendy. However what you have done is that by observation, you have profiled me. Now imagine if that was a web application, where this happens all the time. By letting them access your data - your APML file - you can change that. I’ve actually done this with my friend before, which supports APML. It had ranked a concept as high based on things I had read, which was wrong. So what I did, was changed the score to -1.0 for one of them, because that way, my friend would never show me content on things it thought I would like.

    3) Privacy
    I joined the APML workgroup for this reason: it was to me a smart away to deal with the growing privacy issue on the web:

    • who can see information about you
    • when can people see information about you:
    • what information they can see about you

    The way APML does that is by allowing me to create ‘profiles’ within my APML file; allowing me to export my APML file from a company; and by allowing me to access my APML file so I can see what profile I have.

    4) Shared data
    An APML file can, with your permission, share information between your web-services. My concepts ranking books on Amazon.com, can sit alongside my RSS feed rankings. What’s powerful about that, is the unintended consequences of sharing that data. For example, if Amazon ranked what my favourite genres were about books - this could be useful information to help me filter my RSS feeds about blog topics. The data generated in Amazon’s ecosystem, can benefit me and enjoy a product in another ecosystem, in a mutually beneficial way.

    5) You’re the boss!
    By being able to generate APML for the things you give attention to, you are recognising the value your attention has - something companies already place a lot of value on. Your browsing habits can reveal useful information about your personality, and the ability to control your profile is a very powerful concept. It’s like controlling the image people have of you: you don’t want the wrong things being said about you.  

    If you want to know more about APML, you can check-out it's official website: http://www.apml.org

    Currently rated 4.2 by 5 people

    • Currently 4.2/5 Stars.
    • 1
    • 2
    • 3
    • 4
    • 5


    Welcome


    Mohammad Mahdi Ramezanpour
    Welcome to my website. Hope you can get something useful here. For more information about me and ways you can contact, please use site menu.

    Main Menu

    Sign in