Follow in Twitter & Facebook



Like in Facebook

Powered By Blogger Widgets

Free Download

FREE Tools



Monday, August 6, 2012

Cross page posting Asp.Net

In this article we will discuss about cross page posting in Asp.Net Also you can check my last article on Advantages and disadvantages of asp.net cookies.

Cross page posting is a very useful technique for transforing information between pages. This is a very simple technique. This is available to those control which implements IButtonControl interface like Button, imagebutton, LinkButton etc. It depends on PostBackUrl url property of the controls.

<asp:LinkButton runat="server" ID="lnkButton" PostBackUrl="2ndPage.aspx" Text="Go to 2nd Page" />

Here is the example:

First Page HTML Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FirstPage.aspx.cs" Inherits="FirstPage" %>

<!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>First Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/SecondPage.aspx">Go to 2nd Page</asp:LinkButton>
    </div>
    </form>
</body>
</html>
Here in the link button we have given the PostBackUrl.

Now in the second page we will retrieve the value as below:

Second page .cs code:

protected void Page_Load(object sender, EventArgs e)
    {
        if (PreviousPage != null)
        {
            lblStatus.Text = "Your last page title: " + PreviousPage.Title;
        }
    }

Here in the label it will show the previous page title.




0 on: "Cross page posting Asp.Net"