__________     __ __     __  _______    ________
  / ____/ __ \   / // /    / / / /  _/ |  / / ____/
 / / __/ / / /  / // /_   / /_/ // / | | / / __/
/ /_/ / /_/ /  /__  __/  / __  // /  | |/ / /___
\____/\____/     /_/    /_/ /_/___/  |___/_____/

 --- A GOPHER-LIKE INTERFACE FOR HIVE BLOCKCHAIN ---

The Postback Model - Cross-Page Posting (ASP.NET Tutorial)

BY: @coderlovely | CREATED: March 6, 2018, 10:58 a.m. | VOTES: 0 | PAYOUT: $0.00 | [ VOTE ]

Lesson Objectives

A. Working with Postback Model
B. Implement Cross-Page Posting in Forms
C. Steps for Cross-Page Postback Demo

Needs are;

A.Asp.NET
B. Visual Studio
C. C#

The difficulty level of commands we use is middle.

The Postback Model

ASP.NET uses the Postback Model in which the browser sends the page to the server when an event such as the click of a button happens. The event handlers are then evaluated on the server. After the evaluation, the result is produced on the same page and rendered to the browser. The controls on a web form can do a postback of the form. The Button control automatically does a postback every time a user clicks it. But some controls such as ListBox or RadioButton does not automatically do a postback of the form. The programmer can assign the AutoPostBack property for these controls to "true" to automatically postback when a user selects an item in the ListBox or selects a RadioButton.

Demonstration : Handling Postback event and displaying the country selected in the DropDownList.

The PostBackDemo.aspx file:




PostBack Demo






 









The PostBackDemo.aspx.cs file :
using System;
public partial class PostBackDemo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ddlCountry.Items.Add("India");
ddlCountry.Items.Add("China");
ddlCountry.Items.Add("Japan");
}
if(Page.IsPostBack)
{
lblMessage.Text = " You have selected : " + ddlCountry.SelectedValue;
}
}
}

Run and view output 1 :

[IMAGE: https://i.hizliresim.com/XP84Y5.png]

Cross-Page Posting

Cross-Page Posting is the process by which an asp.net web page performs a post back to another asp.net web page. Button, ImageButton and LinkButton controls contains a property called PostBackUrl which points to the destination page to which the current page will postback. The destination page can access the source page controls through Page.PreviousPage property which returns the reference of previous page. The FindControl method to get the reference to controls on the previous page.

Note : Server.Transfer() is another method used in ASP.NET to perform Cross Page Posting. Server.Transfer() method results in additional processing overheads when compared to using PostBackUrl property.

Cross-Page post back is done from CrossPagePostbackSource web page to CrossPagePostbackDestination web page. User enters the LoginID and Password in the CrossPagePostbackSource web page and clicks the Enter. A Cross-Page post back occurs and the CrossPagePostbackDestination web page displays the LoginID and Password by accessing the LoginID and Password in the CrossPagePostbackSource web page.

Steps for Cross-Page Postback Demo

  1. ) Create The CrossPagePostbackSource web page

The CrossPagePostbackSource.aspx is created using Single-Page File Model

<%@ Page Language="C#" %>


Cross Page Postback Demo









Login ID




Password:




Enter








2 ) Create The CrossPagePostbackDestination web page

The CrossPagePostbackSource.aspx is created using Code-Behind File Model Code for CrossPagePostbackDestination.aspx .cs using System; using System.Web.UI.WebControls;

public partial class CrossPagePostbackDestination : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
{
if (PreviousPage.IsCrossPagePostBack)
{
TextBox txtLogin ;
TextBox txtPassword;
txtLogin = (TextBox)PreviousPage.FindControl("txtLogin");
txtPassword = (TextBox)PreviousPage.FindControl("txtPassword");
Response.Write("
" + "Login ID is "+ txtLogin.Text + "
");
Response.Write("
" + "Password is " + txtPassword.Text
+ " ");
}
}
}
}

Note : Nothing needs to be done in the CrossPagePostbackDestination.aspx file.

3 ) Run the CrossPagePostbackSource web page and enter the LoginID and Password and click Enter.

[IMAGE: https://i.hizliresim.com/NZ8AyX.png]

4 ) Verify the output in CrossPagePostbackDestination page.

[IMAGE: https://i.hizliresim.com/gOvoz5.png]

Posted on Utopian.io - Rewarding Open Source Contributors

TAGS: [ #utopian-io ] [ #utopian ] [ #utopianio ] [ #html ] [ #java ]

Replies

@cha0s0000 | March 6, 2018, 2:23 p.m. | Votes: 0 | [ VOTE ]

Your contribution cannot be approved because it is not as informative as other contributions. See the Utopian Rules. Contributions need to be informative and descriptive in order to help readers and developers understand them.
- ASP/doc is not a correct repository
- Pls use the tutorial template next time.

You can contact us on Discord.
[utopian-moderator]

[ BACK TO TRENDING ] [ BACK TO MENU ]
CMD>