0

I have a data form that performs some calculations upon button press. Once this button is pressed, an object of a static class is instantiated. This object calls different methods in various other classes too.

I have designed these classes in such a way that if any error is thrown, the exception would be handled and the class method would display the error message in asp:ValidationSummary.
Now, when from this data form, i try to save my values, even though, the validationSummary is displaying errors on the forms, the invalid values get saved in the database.

I can create a static property called IsValid in this external class, which is set to false everytime an exception is thrown by the method, however since these methods are repeatedly called by the objects, this property is set back to true if there isn't any exception thrown, thus resulting in bypass of IF condition.

Is there a way to handle such scenario?

Here is the method that is throwing exceptions. This method belongs to a class ClsOmChallan. The .dll file is refered in my project, nothing else.

public static double getResultFromAstmTables(string TableName, double ObserveTemp, double ObserveGravity)
    {
        SqlConnection conn = new SqlConnection(clsConnection.ConnectionString);
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = System.Data.CommandType.Text;
        cmd.Connection = conn;
        cmd.CommandText = "select result from astm_tables where table_no = '" + TableName + "' and temperature = '" + ObserveTemp + "' and gravity = '" + ObserveGravity + "'";

        try
        {

            conn.Open();

            double result1;
            result1 = Convert.ToDouble(cmd.ExecuteScalar());
            isValid = true;
            return result1;
        }
        catch (Exception ex)
        {
            ValidationError.Display("clsAstmTables + getResultsFromAstmTables " + ex.Message.ToString());
            isValid = false;
            return 0;

        }
        finally
        {
            if (conn.State == System.Data.ConnectionState.Open) conn.Close();
            cmd.Dispose();
        }

    }
4

1 回答 1

0

您可以尝试使用将在服务器端调用您的验证方法的验证器。验证器知道显示验证摘要并停止页面处理。

另外,你可以试试

 public override void Validate() {
            //put your logic here
            // Now perform validation

            base.Validate();
        }  

有关更多详细信息,请查看

于 2013-04-03T06:11:26.033 回答