Hello,
I am currently trying to use a custom method to do CRUD button logic (which buttons should be enabled/disabled) dynamically.
The point of this is to be able to call one method (or its overload during onload of the page) to assign a true/false to the buttons dynamically based on each of their circumstances, this will ease complications related to determining which button should be enabled/disabled.
My issue is not that it does not work, it does. But Radzen doesn't seem to like what I am doing at all.
Currently, my buttons do not actually appear in the page creator, they appear as one massive string of errors that disappear once I run the page, the buttons then operate normally and display normally, here is the error:
Identifier expected {expected} expected Invalid token 'null' in class, struct, or interface member declaration Invalid token '=' in class, struct, or interface member declaration Type expected Invalid token '{' in class, struct, or interface member declaration Tuple must contain at least two elements. Invalid token ',' in class, struct, or interface member declaration Type or namespace definition, or end-of-file expected A namespace cannot directly contain members such as fields or methods '<invalid-global-code>.OnInitialized()': no suitable method found to override The name 'btnUpdater' does not exist in the current context The name 'StateHasChanged' does not exist in the current context The name '__numbers' does not exist in the current context The name '__index' does not exist in the current context
I also have an error where radzen likes to add a global variable arbitrarily to my razor.designer.cs page, this requires me to open up the razor.designer.cs page and manually remove the last variable in my method call every time I run the project.
var btnLogicCalculatorResult = btnLogicCalculator(HasSelectedLot,HasSelectedProduct,args.packagingVerified,HasSelectedCardboard,Globals.HasCardboardSelected);
Globals.HasCardboardSelected does not exist anymore. I got rid of it nearly a week ago. It is now just a regular page variable.
If I remove Globals.HasCardboardSelected from the line of code, the program runs normally without any issues, until it is eventually re-added by radzen, at random.
Here is the method with its overload (called during onload of the page) and an enum i keep around for ease of use (my own ease of use that is), for context:
enum ButtonTypes
{
ProductInfo,
SearchOrder,
SearchProduct,
Add,
Edit,
Delete,
Validate,
UnValidate,
Print
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
// Overload method for "btnLogicCalculator()", This method is functionally similar to the original, except that it takes in additional values to then conduct button CRUD logic to artifically block the user from doing nasty things.
//Example: the Edit button being enabled while there are no records to edit. That kind of nasty.
public List<bool> btnLogicCalculator(bool? LotSelected, bool? ProductSelected, bool? ProductValidated, bool? CardboardSelected)
{
List<bool> btnEnabledList = new List<bool>();
foreach (ButtonTypes button in Enum.GetValues(typeof(ButtonTypes)))
{
switch (button)
{
case ButtonTypes.ProductInfo:
if (LotSelected == false)
{
btnEnabledList.Add(true);
}
else
{
if (ProductSelected == false)
{
btnEnabledList.Add(true);
}
else
{
btnEnabledList.Add(false);
}
}
break;
case ButtonTypes.SearchOrder:
if (LotSelected == false)
{
btnEnabledList.Add(true);
}
else
{
btnEnabledList.Add(false);
}
break;
case ButtonTypes.SearchProduct:
if (LotSelected == false)
{
btnEnabledList.Add(true);
}
else
{
btnEnabledList.Add(false);
}
break;
case ButtonTypes.Add:
if (LotSelected == false)
{
btnEnabledList.Add(true);
}
else
{
if (ProductSelected == false)
{
btnEnabledList.Add(true);
}
else
{
if (ProductValidated == false)
{
btnEnabledList.Add(false);
}
else
{
btnEnabledList.Add(true);
}
}
}
break;
case ButtonTypes.Edit:
if (LotSelected == false)
{
btnEnabledList.Add(true);
}
else
{
if (ProductSelected == false)
{
btnEnabledList.Add(true);
}
else
{
if (CardboardSelected == false)
{
btnEnabledList.Add(true);
}
else
{
btnEnabledList.Add(false);
}
}
}
break;
case ButtonTypes.Delete:
if (LotSelected == false)
{
btnEnabledList.Add(true);
}
else
{
if (ProductSelected == false)
{
btnEnabledList.Add(true);
}
else
{
if (ProductValidated == true)
{
btnEnabledList.Add(true);
}
else
{
if (CardboardSelected == false)
{
btnEnabledList.Add(true);
}
else
{
btnEnabledList.Add(false);
}
}
}
}
break;
case ButtonTypes.Validate:
if (LotSelected == false)
{
btnEnabledList.Add(true);
}
else
{
if (ProductSelected == false)
{
btnEnabledList.Add(true);
}
else
{
if (ProductValidated == true)
{
btnEnabledList.Add(true);
}
else
{
btnEnabledList.Add(false);
}
}
}
break;
case ButtonTypes.UnValidate:
if (LotSelected == false)
{
btnEnabledList.Add(true);
}
else
{
if (ProductSelected == false)
{
btnEnabledList.Add(true);
}
else
{
if (ProductValidated == true)
{
btnEnabledList.Add(false);
}
else
{
btnEnabledList.Add(true);
}
}
}
break;
case ButtonTypes.Print:
if (LotSelected == false)
{
btnEnabledList.Add(true);
}
else
{
if (ProductSelected == false)
{
btnEnabledList.Add(true);
}
else
{
if(ProductValidated == false)
{
btnEnabledList.Add(true);
}
else
{
btnEnabledList.Add(false);
}
}
}
break;
default:
break;
}
}
return btnEnabledList;
}
//--------------------------------------------------------------------------------------------###----------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
// OnLoad button disabler, This method will be called when the ProductLotPage is first loaded, See Radzen Page - Events - Load:2 Invoke. for exact moment the method is invoked by radzen.
public List<bool> btnLogicCalculator()
{
List<bool> btnEnabledList = new List<bool>();
foreach (ButtonTypes button in Enum.GetValues(typeof(ButtonTypes)))
{
switch (button)
{
case ButtonTypes.ProductInfo:
btnEnabledList.Add(true);
break;
case ButtonTypes.SearchOrder:
btnEnabledList.Add(true);
break;
case ButtonTypes.SearchProduct:
btnEnabledList.Add(true);
break;
case ButtonTypes.Add:
btnEnabledList.Add(true);
break;
case ButtonTypes.Edit:
btnEnabledList.Add(true);
break;
case ButtonTypes.Delete:
btnEnabledList.Add(true);
break;
case ButtonTypes.Validate:
btnEnabledList.Add(true);
break;
case ButtonTypes.UnValidate:
btnEnabledList.Add(true);
break;
case ButtonTypes.Print:
btnEnabledList.Add(true);
break;
default:
break;
}
}
return btnEnabledList;
}
//--------------------------------------------------------------------------------------------###----------------------------------------------------------------------------------------//
Let me know if you would like more context/have questions about the issue. I'm here all week.
Thank you for your time,
Jacob