The previous time uses the Ext.net realization in the codebehind the dynamic generation form item to the Formpanel, and realizes the table item saves, has found several questions in the process of doing:
①, in the background to add Directclick event to button, although can add success, but click on the button execution will be reported 500 error.
So instead of in the foreground JS to get the data, and then use the Directmethod.request method to call the general processing program to achieve data storage, the code is as follows:
1 functionSave (Stridcontrol) {2 vardata =eval (stridcontrol);3 if(Data.length > 0) {4 varSaveflag =true;5 varRetValue =NewArray ();6 for(i = 0; i < data.length; i++) {7 varControl =ext.getcmp (Data[i]. ControlID);8 varValue =Control.getvalue ();9 varParentControl =control.ownerct;Ten if(Control.allowblank = =false&& (Value = =NULL|| Value = = "")) { One Control.focus (); A Parentcontrol.focus (); -Saveflag =false; - return; the } - varobj =NewObject (); -Obj.id =data[i].id; -Obj. Value =value; +Retvalue[i] =obj; - } + if(Saveflag = =true) { A Ext.net.DirectMethod.request ({ atURL: "Saveservice.ashx", -Method: "Post", -Clearrequest:true, - params: { - Submit:retvalue - }, inSuccessfunction(Result) { - alert (result); to } + }); - } the}
View Code
②, JS through the params to pass parameters to the general processing program, through the context. request.params["Submit" found data not available for delivery
Later, we looked at the data in the context and found that the data we passed was in request.params["Submitdirecteventconfig" in the form of a JSON string:
③, how to get the data we need from the JSON string above, the exact code is as follows:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingext.net;namespacetestfunctions{/// <summary> ///Summary description of Saveservice/// </summary> Public classSaveservice:ihttphandler { Public structParams { Public intID {Get; Set; } Public stringValue {Get; Set; } } Public structExtraparamsconfig { Public ObjectSubmit {Get; Set; } } Public structConfig { Public string__eventtarget {Get; Set; } Public string__eventargument {Get; Set; } Public ObjectExtraparams {Get; Set; } } Public structDirecteventconfig { PublicConfig Config {Get; Set; } } Public voidProcessRequest (HttpContext context) {context. Response.ContentType="Text/plain"; string directeventconfig = context. request.params["Submitdirecteventconfig"]; Directeventconfig eventconfig= JSON. Deserialize<directeventconfig> (Directeventconfig); Objectobj =EventConfig.Config.extraParams; stringstr =obj. ToString (); Extraparamsconfig Extra= JSON. Deserialize<extraparamsconfig>(str); ObjectSubmit =Extra. Submit; List<Params> list = JSON. Deserialize<list<params>>(submit.) ToString ()); Context. Response.Write (JSON. Serialize ("Hello the World")); } Public BOOLisreusable {Get { return false; } } }}
This is achieved through multiple deserialization, and the final list gets the data we need.
Ext.net using Directmethod.request to invoke a generic handler (. ashx) and pass parameters