everybody; I have this problem in asp.net, I have a page where I insert and modify data, before saving I make a validation if it passes I save the data but if not I raise an exception and show it, the function goes like this;
protected void btnSave_Click(object sender, EventArgs e) { try { ... if(ValidData()) //Save ... else throw new Exception('Invalid data'); } catch(Exception ex) { // Javascript alert JSLiteral.Text = Utilities.JSAlert(ex.Message); } }
The problem is that after I raise the exception and fix the data in the page I click again the save button and it saves but before it shows me again the exception message and its annoying. Even when the data is saved I click again and it shows the message from the exception again.
Do you know the answer for this issue?
If JSLiteral is a server side control and it’s using view state. Then you’d need to clear the state of the control, when the save is succesful.
You could disable the viewstate for the control like JSLiteral.EnableViewState =false;