Paip. PHP-asp-jsp implements WEBFORM-based event mechanism development. Paip. PHP-aspjsp implements WEBFORM-based event mechanism development... 1CODEBehind code separation... 1 Page control... 1. implement a form... 2. save VIEWSTATE... 2Page_Ini event and paip. PHP-asp-jsp implements WEBFORM-based event mechanism development
Preface... 1
CODE Behind CODE separation... 1
Page control... 1
Implement a form... 2
Save status VIEWSTATE... 2
Page_Ini events and Page_Load events... 3
Implement the button#click event... 4
Implement the button2_click event... 4
Note: webform. CodeFile. php source code... 5
Preface
We all know that asp.net is developed based on WEBFORM, which is easy to understand and based on the event mechanism. The development efficiency is much faster than that of MVC ..
PHP, ASP, and JSP can also be developed using WEBFORM. here we use PHP as an example to illustrate how to develop WEBFORM ..
CODE Behind CODE separation
To implement Code separation, in addition to MVC, Code-Behind technology can also be used for implementation, which is simpler and faster than MVC. it is also easy to implement modularization and componentization.
In my project, we implement two pages: one with HTML code on the interface, named webform. php, and the other with code named webform. CodeFile. php.
To implement CODE Behind, add the following CODE to the first line of webform. php:
Page control
In ASP. In. NET, we use RUNAT = "SERVER" to indicate that an HTML control can be referenced on the SERVER .. in PHP, it needs to be implemented in a flexible way.
LABEL control:
Textbox control:
Implement a form
Here we need a LABLE, a TEXTBOX control, and two button controls ..
When you click the 1st button, set the LABLE and TEXTBOX values to button1 click...
When you click the second button, set the LABLE value to the input value in TEXTBOX.
The code is as follows:
Save VIEWSTATE
In the CODE Behind file, we write CODE for webform. CodeFile. php... to save the control status on the front-end interface .. When the interface is submitted and the return result is ..
// Maintain the control status and manage viewstate
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 and Page_Load events
When we access this form for the first time, the Page_Ini event is triggered. every time we access this page, the Page_Load event will always be triggered ..
// Page Event Registration
EventReg4Page ();
Function Page_Ini ()
{
Echo "page ini event ";
Global $ labelemeditext;
$ Labelemeditext = "Page_Ini click ";
Global $ textboxshorttext;
$ Textboxshorttext = "Page_Ini click ";
}
Function Page_Load ()
{
Echo "page load event ";
}
Implement the button#click event
// Control event registration
EventReg ("Button1", button#click );
// Button control Button1 click event
Function button#click ()
{
Global $ textboxshorttext;
$ Textboxshorttext = "button1 click ";
Global $ labelemeditext;
$ Labelemeditext = "button1 click ";
}
// Event Registration
Function eventReg ($ controlName, $ controlEvent)
{
If ($ _ POST [$ controlName])
$ ControlEvent ();
}
Implement the button2_click event
// Button control Button2 click event
Function Button2_Click ()
{
Global $ textboxshorttext;
// $ Textboxshorttext = "button2 click ";
Global $ labelemeditext;
$ Labelshorttext = $ textboxshorttext;
}
Note: webform. CodeFile. php source code
// Maintain the control status and manage viewstate
Viewstate ();
// Control event registration
EventReg ("Button1", button#click );
EventReg ("Button2", Button2_Click );
// Page Event Registration
EventReg4Page ();
Function Page_Ini ()
{
Echo "page ini event ";
Global $ labelemeditext;
$ Labelemeditext = "Page_Ini click ";
Global $ textboxshorttext;
$ Textboxshorttext = "Page_Ini click ";
}
Function Page_Load ()
{
Echo "page load event ";
}
// Button control Button1 click event
Function button#click ()
{
Global $ textboxshorttext;
$ Textboxshorttext = "button1 click ";
Global $ labelemeditext;
$ Labelemeditext = "button1 click ";
}
// Button control Button2 click event
Function Button2_Click ()
{
Global $ textboxshorttext;
// $ Textboxshorttext = "button2 click ";
Global $ labelemeditext;
$ Labelshorttext = $ textboxshorttext;
}
// ----------------- The following functions can be used as public functions, including -------------------
// 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 ");
}
// Register the Page_Load event
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 );
}
}
?>
Introduction to terrawebform development... 1 CODE Behind CODE separation... 1 Page control... 1. implement a form... 2. save VIEWSTATE... 2 Page_Ini events and...