GridWeb displays a dropdown with the different possible values. Everything looks correct.
However when I type a “wrong” value in this cell, I got no error message. The only thing I can see is red cross in the cell.
Moreover the OnCellModifiedOnAjax handler is not called. This means that I have no possibility to have a custom handling of this error.
In fact, when the value is not “correct” I need to display a dialog with an error message and automatically restore cell to its previous value. That is exactly the Excel behaviour so why it’s not the same for GridWeb ?
Well, Aspose.Cells.GridWeb has its own interface and style. It has its own way to handle data validation in the sheet. So, if an Excel file has data validation applied, it won’t display message box or alert, rather if you input wrong value it will show red crosses. You may see the error message and title as a tool tip message though when you place the mouse cursor over the cell. You can also use ForceValidation Boolean attribute of GridWeb if you need validation should be compulsory. Moreover, invalid value won’t be stored too.
Well, it’s not exactly what I see in the tooltip on IE 11.
In my web application, the submission of data is not made by GridWeb submit button. It’s just a custom button. My data validation is computed in OnCellModifiedOnAjax handler using the GridComment class and then handled client side by OnCellUpdatedClientFunction by displaying an error dialog. In this case, it does not work because this event is not fired when the input cell value is not correct.
As I previously said, my need is to copy the Excel behaviour: when the value is not “correct” the GridWeb should display a dialog with an error message and automatically restore cell to its previous value.
Thanks for sharing further details and screenshot.
I have logged your feature request as an improvement to existing feature regarding data validation. I have logged the ticket as following:
CELLSNET-45928 - Data validation - GridWeb should display a dialog with an error message if inserting wrong value and automatically restore cell to its previous value
Our concerned developer from product team will evaluate your issue soon.
Once we have an update on it, we will let you know here.
We can’t say or commit anything at the moment. The feature itself demands thorough evaluation and investigation. Our Chinese team is only holidays these days on their spring festival. We will try to evaluate it in the next week (if possible), then we might be able to comment on it.
Do you have any workaround that will help me to wait this fix ? I mean for example overriding one of your javascript function to make a postback that will call the OnCellModifiedOnAjax server handler ?
I am afraid, I have no workaround to cope with it, we will further check to try to find one though. Please spare us some time so our concerned developer from product team could evaluate your requested feature in details.
Once we have any new information, we will share it with you.
We have found a workaround. Well, you can perform your desired task when validation fails. You can write your business logic on client side. Please use/handle OnCellErrorClientFunction which gets or sets the client side function name to be called when a cell’s validation is failed.
e.g Sample code:
/// <summary>
/// Gets or sets the client side function name to be called when a cell's validation is failed.
/// The client function should be declared like this:<br/>
/// function MyOnCellError(cell)<br/>
/// {<br/>
/// alert(GridWeb1.getCellValueByCell(cell));<br/>
/// }<br/>
/// <br/>Note: You may use the "this" pointer in the client function to point the grid control which fires the event.
/// </summary>
We will check but if cell validation fails and you either submit the web page or navigate to other sheets, the older (valid) value in the cell would be set automatically.
Since we already logged a ticket with an id “CELLSNET-45928” for your issue, so, kindly let the investigation/evaluation of your issue is complete by the concerned developer from product team. Hopefully, we will update you in the next week.
As you need the error messages must be computed on server side so, we need to reconsider your requirements, it would be completely different implementation way. I have reopened your ticket “CELLSNET-45928” again. We will try to support your needs soon.
Once we have any new information, we will share it with you.
We will add: GridValidationType.CustomServerFunction in one of our upcoming fixes to support your requirements. The code could be something like following:
e.g Sample code:
//first you need to implement the interface:GridCustomServerValidation
class myservervali : GridCustomServerValidation
{
//if return string.empty the validate is passed,else you can return any related message which can be deal in ClientCallback function
public string Validate(GridWorksheet sheet, int row, int col, string value)
{
if (row == 1)
{//validate fail
return "not passed";
}
else
{//validate ok
return string.Empty;
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack&&!GridWeb45928.IsPostBack)
{
var gridValidationCollection = this.GridWeb45928.ActiveSheet.Validations;
GridValidation gv = gridValidationCollection.Add();
gv.AddArea(new GridCellArea(1,1,2,2));
gv.ValidationType = GridValidationType.CustomServerFunction;
gv.ServerValidation = new myservervali();
//also need to set ClientValidationFunction to deal with client logic when server validation fails and return message
gv.ClientValidationFunction = "ValidationErrorClientFunction";
}
}
.aspx page:
<script type="text/javascript" language="javascript">
var lastselectvalue = null;
function myCellSelect(cell) {
var value = this.getCellValueByCell(cell);
lastselectvalue = value;
console.log("myonCellSelect:" + value + " row" + this.getCellRow(cell) + ",col:" + this.getCellColumn(cell));
}
//decalare like this
function ValidationErrorClientFunction(cell,msg) {
//Showing an alert message where "this" refers to GridWeb
alert(this.id + msg);
console.log("myonCellSelect:" + this.getCellRow(cell) + ",col:" + this.getCellColumn(cell));
//
var who = this;
//async raise alert
//restore to valid value
who.setValid(cell);
setInnerText(cell.children[0], lastselectvalue);
// this.setCellValueByCell(cell, lastselectvalue);
}
</script>
......
<cc1:GridWeb ID="GridWeb45928" runat="server" OnCellSelectedClientFunction="myCellSelect" >