Paip. php-asp-jsp implement event mechanism WebForm development _php Tutorial

Source: Internet
Author: User
Paip. PHP-ASP-JSP implementation of event mechanism WebForm-type development

Objective... 1

Code behind codes separation ... 1

Page control ... 1

Implement a form ... 2

Implementation status ViewState Save ... 2

Page_ini events and Page_Load events ... 3

Implement Button1_Click Events ... 4

Implement Button2_Click Events ... 4

Note: WebForm. codefile.php Source ... 5

Objective
We all know that ASP. NET is developed in a webform, easy to understand, event-based mechanism. Development efficiency is much faster than the MVC approach.

Php,asp,jsp can also be developed in WebForm, where we use PHP as an example to illustrate how to develop WebForm.

Code behind separation
If you need to implement code separation, in addition to MVC, you can use the Code-behind technology to achieve, simpler, more efficient development than MVC is much faster. And it is easy to implement modularity, assembly

In me we implement two pages, an interface HTML code, named webform.php, a put code, called WebForm. codefile.php

To implement code Behind, add the following code to the first line of webform.php:

Page controls
in ASP. NET, we are using runat= "SERVER" to indicate that an HTML control can be referenced on the server side: In PHP, you need to use a workaround to implement

Label control:

TextBox control:

Implement a form
Here we need a lable, a TextBox control, two Button controls:

Our request is that when you click the 1th button, the lable and TextBox values are set to button1 click ...

When you click the second button, set the lable value to the input value in the textbox

The total code is as follows

Implement state ViewState Save
In the code behind file, WebForm. codefile.php: We write code to implement the foreground interface control state save. When the interface is committed, the value of the control is returned:

Maintain control state, viewstate management

ViewState ();

__viewstate

function ViewState ()

{

foreach ($_request as $color) {

$key =key ($_request);

$controlName = $key. " _text ";

Echo ($key. " ---". $color."
");

Global $ $controlName;

$ $controlName = $color;

Next ($_request);

}

}

Page_ini Events and Page_Load events
The Page_ini event is triggered when we first access this form,.. Every time you visit this page, the Page_Load event is always triggered.

Page Event Registration

Eventreg4page ();

function Page_ini ()

{

echo "page ini event";

Global $Label 1_text;

$Label 1_text= "Page_ini click";

Global $TextBox 1_text;

$TextBox 1_text= "Page_ini click";

}

function Page_Load ()

{

echo "Page Load event";

}

Implementing the Button1_Click Event

Control Event Registration

Eventreg ("Button1", button1_click);

Click events for Button controls Button1

function button1_click ()

{

Global $TextBox 1_text;

$TextBox 1_text= "button1 Click";

Global $Label 1_text;

$Label 1_text= "button1 Click";

}

Event Registration

function Eventreg ($controlName, $controlEvent)

{

if ($_post[$controlName])

$controlEvent ();

}

Implementing the Button2_Click Event
Click events for Button controls Button2

function button2_click ()

{

Global $TextBox 1_text;

$TextBox 1_text= "Button2 click";

Global $Label 1_text;

$Label 1_text= $TextBox 1_text;

}

Note: WebForm. codefile.php Source

Maintain control state, viewstate management

ViewState ();

Control Event Registration

Eventreg ("Button1", button1_click);

Eventreg ("Button2", button2_click);

Page Event Registration

Eventreg4page ();

function Page_ini ()

{

echo "page ini event";

Global $Label 1_text;

$Label 1_text= "Page_ini click";

Global $TextBox 1_text;

$TextBox 1_text= "Page_ini click";

}

function Page_Load ()

{

echo "Page Load event";

}

Click events for Button controls Button1

function button1_click ()

{

Global $TextBox 1_text;

$TextBox 1_text= "button1 Click";

Global $Label 1_text;

$Label 1_text= "button1 Click";

}

Click events for Button controls Button2

function button2_click ()

{

Global $TextBox 1_text;

$TextBox 1_text= "Button2 click";

Global $Label 1_text;

$Label 1_text= $TextBox 1_text;

}

-----------------The following functions can be used as public functions, including in-------------------

Event Registration

function Eventreg ($controlName, $controlEvent)

{

if ($_post[$controlName])

$controlEvent ();

}

Page Event Registration

function Eventreg4page ()

{

if (!$_post)

{

if (function_exists ("Page_ini"))

Call_user_func ("Page_ini");

}

Registering Page_Load Events

if (function_exists ("Page_Load"))

Call_user_func ("Page_Load");

}

__viewstate

function ViewState ()

{

foreach ($_request as $color) {

$key =key ($_request);

$controlName = $key. " _text ";

Echo ($key. " ---". $color."
");

Global $ $controlName;

$ $controlName = $color;

Next ($_request);

}

}

?>

http://www.bkjia.com/PHPjc/477976.html www.bkjia.com true http://www.bkjia.com/PHPjc/477976.html techarticle Paip. php-aspjsp implement event mechanism WebForm development Preface ... 1 code behind codes separate ... 1 Page Control ... 1 Implement a form ... 2 Implementation status ViewState save ... 2 Page_ini events with ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.