PHP analog ASP. Webfrom Button Submit Event instance, asp.netwebfrom_php tutorial

Source: Internet
Author: User

PHP analog ASP. Webfrom Button Submit Event instance, Asp.netwebfrom


Because the company needs PHP project development, PHP just get started, in the Write button submission process, the button event in ASP. First look at the following code,

<?require_once '. /inc/eventhelper.php '; function Page_Load () {echo ' will run at any time
'; if (! Page::ispostback ()) {echo ' Load product category
' If ($_get[' cmd ']== ' edit ') {echo ' modifies the loading of product information that needs to be modified
';}}} function Badd_click () {//COMM::CHECKQX (' Product management _ add '); echo "Badd_click
";} function Bedit_click () {//COMM::CHECKQX (' Product Management _ Modify '); Echo ' proid= '. $_get[' proid ']. '
'; Echo ' Bedit_click
";} function Sdfsdfdsf_click () {echo ' e44444444444444444444
";}? >

The above code should be a bit familiar to the ASP, such as: Page_load,page.ispostback,badd_click, which are like the events of ASP.

The above code runs the Badd_click function when the "Add" button is clicked (for the time being, functions seem to mean the function), and similarly, clicking the "Modify" button automatically runs the Bedit_click event. Do not need too many parameter changes, and do not need too many files, if the page function is not very complex situation, with this mode can be developed quickly.

Here's a look at the code for this eventhelper.php file:

<?class page{//Whether postback data, 1: Is public static function IsPostBack () {global $SYSRunEventName; return!empty ($ Sysruneventname);} Load and Execute event function eventload () {global $SYSRunEventName; $arrEvent =get_defined_functions (); $arrEventUser = $arrEvent [ ' User '; $arr =array_keys ($_post); foreach ($arr as $row) {$name =strtolower ($row); foreach ($arrEventUser as $row 1) {$ Name1=str_ireplace (' _click ', ' ', $row 1); if ($name = = $name 1) {$SYSRunEventName = $row 1;break;}} if (!empty ($SYSRunEventName)) {break;}} if (function_exists (' Page_Load ')) Page_Load (); $SYSRunEventRunName =strtolower ($SYSRunEventName); if (page::i Spostback ()) {$SYSRunEventName ();}}} Class Comm{public static function GetParam ($params =array (), $cmd = ' addoverride ') {$allParam =array (); if ($cmd = = ' Addoverride ') {$arrKeys =array_keys ($params); foreach ($arrKeys as $row) {if (!in_array ($row, Array_keys ($allParam))) $ allparam[$row]= $params [$row];}} else if ($cmd = = ' del ') {foreach ($params as $row) {unset ($_get[$row]);}} $arrKeys =array_keys ($_get), foreach ($arrKeys as $row) {if (!in_array ($row, ArraY_keys ($allParam))) $allParam [$row]=$_get[$row];} $p = "; $arrKeys =array_keys ($allParam); foreach ($arrKeys as $row) {$p. = $row. ' = '. $allParam [$row]. ' & ';} return RTrim ($p, ' & ');}} Page::eventload ();? >

All of the above features can be tested under my php5.4 can be run successfully, but in terms of security has not been considered too much, read some articles PHP will be possible to execute PHP code through the client, because PHP is a lot of practical features.

About Comm::getparam, because you often need to get parameters for Get mode, or modify parameters, such as paging needs to keep all the URL parameters, only to modify the paging parameters (such as page=5), so you write some code yourself.

The main use of PHP following several features:

Function_exists
Get_defined_functions

and using the principle of common form submission, using the submit principle to implement the function.

Because of the time rush, too late to explain the specific principles, but also forgive me, code can be understood by everyone.


The ASPNET validation control instance, what I'd like to know is the event code of the form's Submit button?

How do I trigger the text of a validation control? Error message when validation fails this way, the interior should be a variety of verification methods, such as regular expressions.

How to invoke the Click event of another button in the ASPNET button click event Beginner, Know,

Method One: Specify the event directly






Method Two: Background add
protected void Page_Load (object sender, EventArgs e)
{
Button btn;
btn= new Button ();
Btn.id = "BTN1";
Btn. Text = "button 1";
THIS.FORM1.CONTROLS.ADD (BTN);
Btn. Click + = new EventHandler (Btn1_click);

BTN = new Button ();
Btn.id = "BTN2";
Btn. Text = "button 2";
THIS.FORM1.CONTROLS.ADD (BTN);
Btn. Click + = new EventHandler (Btn1_click);
}

protected void Btn1_click (object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript (Page.gettype (), "", "

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.