Grid Inserting Server Event Issue

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
prem01628
User
Posts: 23

Grid Inserting Server Event Issue

Post by prem01628 »

In asp.net maker 12.0.4, I put the code under Grid Inserting in Server Event in my project
but its not working , it bypass the validation

public bool Grid_Inserting() {
// Enter your code here
// To reject grid insert, set return value to FALSE

var rsnew = GetGridFormValues(); // Get the form values of the new records as an array of array
//ew_End(rsnew); // Print the records and end the script
int sum = 0;
foreach (OrderedDictionary row in rsnew) // Loop through the new records
sum += Convert.ToInt32(row["amt"]);
if (sum < 100) {
// To cancel, set return value to false
CancelMessage = "The total sale must be more than 100.";
return false;
}
return false;
}

even it return the false on both conditions.

Even in Grid Inserted event i un-comment the ew_Write statement
but same issue, no activity found.
instead of display "Grid Inserted" grid insert complete and all grid records inserted successfully
where is the problem? i can't understand, plz help

// Grid Inserted event
public void Grid_Inserted(List<OrderedDictionary> rsnew) {
ew_Write("Grid Inserted");
}


Webmaster
User
Posts: 9427

Post by Webmaster »

Thank you for reporting. This is an error and will be fixed in the next build.

In the mean time, please fix by modifying the template file "page-class.cs" (add the Grid_Inserting/Grid_Inserted event behind line 100):

...
<!--## if (id != "master") { // ASPX ##-->
<!--##GetServerEvent("Table","Grid_Inserting","",true)##-->
<!--##GetServerEvent("Table","Grid_Inserted","",true)##-->
<!--##GetServerEvent("Table","Row_Inserting","",true)##-->
...


prem01628
User
Posts: 23

Post by prem01628 »

Thanx for reply

I added these line. it works but further issued is traced....

Error is
Specified argument was out of the range of valid values.
Parameter name: index

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: index

Source Error:

Line 895: // Ignore
Line 896: } else {
Line 897: rows[rowindex] = GetFieldValues("FormValue"); // Return row as array
Line 898: }
Line 899: }

Source File: c:\inetpub\wwwroot\test\App_Code\_test_dll\saledetailslist.cs Line: 897

the problem in GetGridFormValues() , plz give the solution


Webmaster
User
Posts: 9427

Post by Webmaster »

Try (see lines marked with ***):

  1. page-class.cs:

<!--## if (id != "master") { // ASPX ##-->
<!--##GetServerEvent("Table","Row_Inserting","",true)##-->
<!--##GetServerEvent("Table","Row_Inserted","",true)##-->
<!--##GetServerEvent("Table","Row_Updating","",true)##-->
<!--##GetServerEvent("Table","Row_Updated","",true)##-->
<!--##GetServerEvent("Table","Row_UpdateConflict","",true)##-->
<!--##GetServerEvent("Table","Row_Deleting","",true)##-->
<!--##GetServerEvent("Table","Row_Deleted","",true)##-->
<!--##GetServerEvent("Table","Grid_Inserting","",true) //##-->
<!--##GetServerEvent("Table","Grid_Inserted","",true) //
##-->
<!--##GetServerEvent("Table","Grid_Updating","",true) //##-->
<!--##GetServerEvent("Table","Grid_Updated","",true) //
##-->

  1. list-script-function.cshtml:

// Perform Grid Add
public bool GridInsert() {
int addcnt = 0;
bool bGridInsert = false;

		<!--## //*** if (SYSTEMFUNCTIONS.ServerScriptExist("Table","Grid_Inserting")) { ##-->
                    <!--## if (CTRL.CtrlID == "list" && SYSTEMFUNCTIONS.ServerScriptExist("Table","Grid_Inserting")) { //*** ##-->

...

// Get all form values of the grid
//*** public OrderedDictionary GetGridFormValues() {
public List<OrderedDictionary> GetGridFormValues() { //***

// Get row count
ObjForm.Index = -1;
int rowcnt = ew_ConvertToInt(ObjForm.GetValue(FormKeyCountName));
	if (ew_Empty(rowcnt) || !Information.IsNumeric(rowcnt))
			rowcnt = 0;
		//*** var rows = new OrderedDictionary();
                    var rows = new List<OrderedDictionary>(); //***
		// Loop through all records
		for (int rowindex = 1; rowindex <= rowcnt; rowindex++) {

			// Load current row values
			ObjForm.Index = rowindex;

			string rowaction = ObjForm.GetValue(FormActionName);
			if (rowaction != "delete" && rowaction != "insertdelete") {

				LoadFormValues(); // Get form values

				if (rowaction == "insert" && EmptyRow()) {
					// Ignore
				} else {
					//*** rows[rowindex] = GetFieldValues("FormValue"); // Return row as array
                                            rows.Add(GetFieldValues("FormValue")); // Return row as array //***
				}
			}
		}
		return rows; // Return as array of array
	}
  1. aspxfn.cs:

// Get field values
//*** public Dictionary<string, object> GetFieldValues(string name) {
public OrderedDictionary GetFieldValues(string name) { //***
//*** var values = new Dictionary<string, object>();
var values = new OrderedDictionary(); //***


prem01628
User
Posts: 23

Post by prem01628 »

I make all the changes..... previous error solved ....but something wrong......

not i encounter new error.......

Server Error in '/test' Application.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'ProcessCustomAction' does not exist in the current context

Source Error:

Line 523:
Line 524: // Process custom action first
Line 525: ProcessCustomAction();
Line 526:
Line 527: // Set up records per page

Source File: c:\inetpub\wwwroot\test\App_Code\_test_dll\saledetailslist.cs Line: 525

my Grid Inserting code are taken from Example.......
// Grid Inserting event
public bool Grid_Inserting() {
// Enter your code here
// To reject grid insert, set return value to FALSE

var rsnew = GetGridFormValues(); // Get the form values of the new records as an array of array
//ew_End(rsnew); // Print the records and end the script
int sum = 0;
 foreach (OrderedDictionary row in rsnew) // Loop through the new records
	sum += Convert.ToInt32(row["amt"]);
if (sum < 1000) {
// To cancel, set return value to false
	CancelMessage = "The total percentages must be 100.";
	return false;
}
 return true;

}


motfs
User
Posts: 258

Post by motfs »

prem01628 wrote:
Compiler Error Message: CS0103: The name 'ProcessCustomAction' does not exist in
the current context

Double check if this function exist in <table>list.cs:

public void ProcessCustomAction() {
...
}

If not sure, regenerate All the files.


prem01628
User
Posts: 23

Post by prem01628 »

i regenerated the all file but the problem is same as it is...

i think this is missing in template files.... or bug in script

please give the complete solution....


motfs
User
Posts: 258

Post by motfs »

You may double check if your modification is correct. ProcessCustomAction() is in list-script-function.cshtml.

If you do not find the following code in the template "list-script-function.cshtml":

public void ProcessCustomAction() {
...
}

You need to download again.


Post Reply