Php simulates the asp.net webFrom button to submit an event instance, asp. netwebfrom

Source: Internet
Author: User

Php simulates the asp.net webFrom button to submit an event instance, asp. netwebfrom

As the company needs php project development, php is just getting started. In the process of writing button submission, the button events in asp.net are better. Let's take a look at the following code,

<? Require_once '../inc/EventHelper. php'; function Page_Load () {echo' will run at any time <br> '; if (! Page: IsPostBack () {echo 'Load Product Category <br> '; if ($ _ GET ['cmd'] = 'edit ') {echo 'modify and load the product information to be modified <br> ';}} function bAdd_Click () {// Comm: CheckQX ('product management_add '); echo "bAdd_Click <br>";} function bEdit_Click () {// Comm: CheckQX ('product management_modify'); echo 'proid = '. $ _ GET ['proid']. '<br>'; echo "bEdit_Click <br>";} function sdfsdfdsf_Click () {echo "e4444444444444444444444 <br>" ;}?>
<Form name = "aa" method = "post" action = "? <? = Comm: GetParam ()?> "> <Input type =" submit "name =" bAdd "value =" add "/> <input type =" submit "name =" bedit "value =" modify "/> <input type = "submit" name = "sdfsdfdsf" value = "ewrewrewr"/> </form>

The above code, such as Page_Load, Page. IsPostback, and bAdd_Click, is familiar with asp.net development.

The above code runs the bAdd_Click function when you click the Add button (function seems to be the function). Similarly, click Modify to automatically run the bEdit_Click event. There is no need for too many parameter changes or too many files. If the page features are not very complex, you can use this mode for rapid development.

Let's take a look at the code of the EventHelper. php file:

<? Class Page {// whether to send data back. 1: public static function IsPostBack () {global $ SYSRunEventName; return! Empty ($ SYSRunEventName);} // load and execute the 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 $ row1) {$ name1 = str_ireplace ('_ click', '', $ row1); if ($ name = $ name1) {$ SYSRunEventName = $ row1; break ;}} if (! Empty ($ SYSRunEventName) {break ;}} if (function_exists ('page _ load') Page_Load (); $ SYSRunEventRunName = strtolower ($ SYSRunEventName); if (Page :: isPostBack () {$ 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 ();?>

You can test the above functions. I have run php5.4 successfully, but I have not considered much about the security. I have read some articles about php and may execute php code on the client, because php has many practical features.

For Comm: GetParam, it is often necessary to obtain get parameters or modify parameters. For example, if all url parameters need to be retained during paging, only paging parameters (such as page = 5) are modified ), so I wrote some code on my own.

It mainly utilizes the following features of php:

Function_exists
Get_defined_functions

And uses common form submission principles to implement functions.

Due to the rush of time, it is too late to describe the specific principles. Please forgive me. You can understand the code.


For the aspnet verification control instance, what do I want to know more about is the event code of the Form submission button?

How to trigger the text of the verification control? If verification fails, an error message is displayed. Various internal verification methods, such as regular expressions, should be used.
 
How can I call the click event of another button in a button click event in ASPnet,

Method 1: Specify the event directly
<Asp: Button ID = "btn1" runat = "server" Text = "Button 1" onclick = "btn1_Click"/> <br/>
<Asp: Button ID = "btn2" runat = "server" Text = "Button 2" onclick = "btn1_Click"/>

Method 2: add in the background
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 (), "", "<script language = \" javascript \ "> alert ('click event '); </script> ");
}

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.