Click here to Skip to main content
15,943,085 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wanted to know can a form still be submitted even with the validation fired? If so, How can I get it to work on this form.

C#
protected void Page_Load(object sender, EventArgs e)
    {
        ButtonPrint.Attributes.Add("onclick", "window.print(); return false");
        this.lblYEAR.Text = DateTime.Today.ToString("yyyy");
        this.TextBoxDATE.Text = DateTime.Today.ToString("dd-MMM-yy");
        TextBoxFTUG.Focus();

        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
        con.Open();
        SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
        con2.Open();

        TextBoxINST_ID.Text = Session["inst_id"].ToString();
        SqlCommand scmd = new SqlCommand("Select INST_ID, LongName, City, State from Table44 where INST_ID = '" + TextBoxINST_ID.Text + "'", con);
        SqlCommand scmd2 = new SqlCommand("Select INST_ID, FT_UNDERGR, FT_GRAD, FTE_UNDERG, FTE_GRAD, NON_CREDIT, TOTAL_FTE, FCFTUHC, FCFTPBHC, FCPTUHC, FCPTPBHC, NCHC, FTEYR from Table2012 where INST_ID = '" + TextBoxINST_ID.Text + "'", con2);
        SqlDataReader dr = scmd.ExecuteReader();
        SqlDataReader dr2 = scmd2.ExecuteReader();
        if (dr.Read())
            if (dr2.Read())
            {
                lblCity.Text = dr["City"].ToString();
                lblState.Text = dr["State"].ToString();
                lblSchool.Text = dr["LongName"].ToString();
                lblLYear.Text = dr2["FTEYR"].ToString();
                TextBoxLYFTUG.Text = dr2["FT_UNDERGR"].ToString();
                TextBoxLYFTG.Text = dr2["FT_GRAD"].ToString();
                TextBoxLYTHUGDR.Text = dr2["FTE_UNDERG"].ToString();
                TextBoxLYTHGDR.Text = dr2["FTE_GRAD"].ToString();
                TextBoxLYNCCDR.Text = dr2["NON_CREDIT"].ToString();
                TextBoxLYTCNC.Text = dr2["TOTAL_FTE"].ToString();
                TextBoxLYTNFUG.Text = dr2["FCFTUHC"].ToString();
                TextBoxLYTNFG.Text = dr2["FCFTPBHC"].ToString();
                TextBoxLYTNCPUG.Text = dr2["FCPTUHC"].ToString();
                TextBoxLYTNCPG.Text = dr2["FCPTPBHC"].ToString();
                TextBoxLYTNNCC.Text = dr2["NCHC"].ToString();



            }
        dr.Close();
        dr2.Close();
        con.Close();
        con2.Close();

        RangeValidatorLYTNFUG.MinimumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNFUG.Text) - Convert.ToInt32(TextBoxLYTNFUG.Text) * 20 / 100);
        RangeValidatorLYTNFUG.MaximumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNFUG.Text) + Convert.ToInt32(TextBoxLYTNFUG.Text) * 20 / 100);

        RangeValidatorLYTNFG.MinimumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNFG.Text) - Convert.ToInt32(TextBoxLYTNFG.Text) * 20 / 100);
        RangeValidatorLYTNFG.MaximumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNFG.Text) + Convert.ToInt32(TextBoxLYTNFG.Text) * 20 / 100);

        RangeValidatorLYTNCPUG.MinimumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNCPUG.Text) - Convert.ToInt32(TextBoxLYTNCPUG.Text) * 20 / 100);
        RangeValidatorLYTNCPUG.MaximumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNCPUG.Text) + Convert.ToInt32(TextBoxLYTNCPUG.Text) * 20 / 100);

        RangeValidatorLYTNCPG.MinimumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNCPG.Text) - Convert.ToInt32(TextBoxLYTNCPG.Text) * 20 / 100);
        RangeValidatorLYTNCPG.MaximumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNCPG.Text) + Convert.ToInt32(TextBoxLYTNCPG.Text) * 20 / 100);

        RangeValidatorLYTNNCC.MinimumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNNCC.Text) - Convert.ToInt32(TextBoxLYTNNCC.Text) * 20 / 100);
        RangeValidatorLYTNNCC.MaximumValue = Convert.ToString(Convert.ToInt32(TextBoxLYTNNCC.Text) + Convert.ToInt32(TextBoxLYTNNCC.Text) * 20 / 100);

    }

    protected void ButtonSubmit_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
        con.Open();

        SqlCommand cmd = new SqlCommand("Insert into Table2013 (INST_ID, FT_UNDERGR, DATE, FT_GRAD, FTE_UNDERG, FTE_GRAD, NON_CREDIT, TOTAL_FTE, FCFTUHC, FCFTPBHC, FCPTUHC, FCPTPBHC, NCHC, FTEYR) values (@INST_ID, @FT_UNDERGR, @DATE, @FT_GRAD, @FTE_UNDERG, @FTE_GRAD, @NON_CREDIT, @TOTAL_FTE, @FCFTUHC, @FCFTPBHC, @FCPTUHC, @FCPTPBHC, @NCHC, @FTEYR)Insert into Table2014 (INST_ID, FT_UNDERGR, DATE, FT_GRAD, FTE_UNDERG, FTE_GRAD, NON_CREDIT, TOTAL_FTE, FCFTUHC, FCFTPBHC, FCPTUHC, FCPTPBHC, NCHC, FTEYR) values (@INST_ID, @FT_UNDERGR, @DATE, @FT_GRAD, @FTE_UNDERG, @FTE_GRAD, @NON_CREDIT, @TOTAL_FTE, @FCFTUHC, @FCFTPBHC, @FCPTUHC, @FCPTPBHC, @NCHC, @FTEYR)", con);

        cmd.CommandType = CommandType.Text;
        cmd.Parameters.AddWithValue("@INST_ID", TextBoxINST_ID.Text);
        cmd.Parameters.AddWithValue("@FT_UNDERGR", TextBoxFTUG.Text);
        cmd.Parameters.AddWithValue("@FT_GRAD", TextBoxFTG.Text);
        cmd.Parameters.AddWithValue("@FTE_UNDERG", TextBoxTHUGDR.Text);
        cmd.Parameters.AddWithValue("@FTE_GRAD", TextBoxTHGDR.Text);
        cmd.Parameters.AddWithValue("@NON_CREDIT", TextBoxNCCDR.Text);
        cmd.Parameters.AddWithValue("@TOTAL_FTE", TextBoxTCNC.Text);
        cmd.Parameters.AddWithValue("@FCFTUHC", TextBoxTNFUG.Text);
        cmd.Parameters.AddWithValue("@FCFTPBHC", TextBoxTNFG.Text);
        cmd.Parameters.AddWithValue("@FCPTUHC", TextBoxTNCPUG.Text);
        cmd.Parameters.AddWithValue("@FCPTPBHC", TextBoxTNCPG.Text);
        cmd.Parameters.AddWithValue("@NCHC", TextBoxTNNCC.Text);
        cmd.Parameters.AddWithValue("@FTEYR", lblYEAR.Text);
        cmd.Parameters.AddWithValue("@DATE", TextBoxDATE.Text);

        cmd.ExecuteNonQuery();
        con.Close();

        if (Page.IsValid)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('You Have Successfully Submitted the Enrollment Profile');", true);
        }
        else
        {
            Response.Redirect("FTEEnrollmentInformation.aspx");
        }

        TextBoxFTUG.Text = string.Empty;
        TextBoxFTG.Text = string.Empty;
        TextBoxTHUGDR.Text = string.Empty;
        TextBoxTHGDR.Text = string.Empty;
        TextBoxNCCDR.Text = string.Empty;
        TextBoxTCNC.Text = string.Empty;
        TextBoxTNFUG.Text = string.Empty;
        TextBoxTNFG.Text = string.Empty;
        TextBoxTNCPUG.Text = string.Empty;
        TextBoxTNCPG.Text = string.Empty;
        TextBoxTNNCC.Text = string.Empty;
        TextBoxTHUG.Text = string.Empty;
        TextBoxTHG.Text = string.Empty;
        TextBoxT1234.Text = string.Empty;
        TextBoxNCC.Text = string.Empty;
        TextBoxTHCAS.Text = string.Empty;
        
        
    }
    public class PCPrint : System.Drawing.Printing.PrintDocument
    {

    }
    protected void ButtonPrint_Click(object sender, EventArgs e)
    {

    }

    protected void TextBoxTHUG_TextChanged(object sender, EventArgs e)
    {
        int i = Convert.ToInt32(TextBoxTHUG.Text);
        int j = 12;
        TextBoxTHUGDR.Text = Convert.ToString(i / j);
        TextBoxTHG.Focus();
    }

    protected void TextBoxTHG_TextChanged(object sender, EventArgs e)
    {
        int i = Convert.ToInt32(TextBoxTHG.Text);
        int j = 9;
        TextBoxTHGDR.Text = Convert.ToString(i / j);


        int a = Convert.ToInt32(TextBoxFTUG.Text);
        int b = Convert.ToInt32(TextBoxFTG.Text);
        int c = Convert.ToInt32(TextBoxTHUGDR.Text);
        int d = Convert.ToInt32(TextBoxTHGDR.Text);
        TextBoxT1234.Text = Convert.ToString(a + b + c + d);
        TextBoxNCC.Focus();

    }

    protected void TextBoxTNNCC_TextChanged(object sender, EventArgs e)
    {
        int a = Convert.ToInt32(TextBoxTNFUG.Text);
        int b = Convert.ToInt32(TextBoxTNFG.Text);
        int c = Convert.ToInt32(TextBoxTNCPUG.Text);
        int d = Convert.ToInt32(TextBoxTNCPG.Text);
        int f = Convert.ToInt32(TextBoxTNNCC.Text);
        TextBoxTHCAS.Text = Convert.ToString(a + b + c + d + f);

    }

    protected void TextBoxNCC_TextChanged(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
        con.Open();

        if (true)
        {
            SqlCommand level = new SqlCommand("Select INST_ID, Calendar from Table44 where INST_ID = @INST_ID", con); 
            level.Parameters.Add(new SqlParameter("INST_ID", TextBoxINST_ID.Text));
            

            SqlDataReader reader = level.ExecuteReader();
            DataTable dt1 = new DataTable();
            dt1.Load(reader);

            foreach (DataRow dr1 in dt1.Rows)
            {
               string returnedLevel = (dr1[1].ToString());
                int inst_id = Convert.ToInt32(dr1[0].ToString());
                Session["inst_id"] = inst_id;

                if (returnedLevel == "Semester")
               {
                   int i = Convert.ToInt32(TextBoxNCC.Text);
                   int j = 168;
                   TextBoxNCCDR.Text = Convert.ToString(i / j);

                   int a = Convert.ToInt32(TextBoxT1234.Text);
                   int b = Convert.ToInt32(TextBoxNCCDR.Text);
                   TextBoxTCNC.Text = Convert.ToString(a + b);
                   TextBoxTNFUG.Focus();
 
               }
               else if (returnedLevel == "Quarter")
               {
                   int i = Convert.ToInt32(TextBoxNCC.Text);
                   int j = 120;
                   TextBoxNCCDR.Text = Convert.ToString(i / j);

                   int a = Convert.ToInt32(TextBoxT1234.Text);
                   int b = Convert.ToInt32(TextBoxNCCDR.Text);
                   TextBoxTCNC.Text = Convert.ToString(a + b);
                   TextBoxTNFUG.Focus();
               }
Posted

1 solution

 
Share this answer
 
Comments
Computer Wiz99 27-Nov-13 9:52am    
Tadit Dash, I see what you are saying. The rangevalidator fires when the number entered is higher or lower by 20%. Will this code work around it and it still will fire? I do need it to still fire and submit.
So, is it working or you still have problems?
Computer Wiz99 27-Nov-13 10:41am    
Well, my problem is to where to put the code.
Set the property for the Button in aspx page, something like this.

<asp:Button ID="ButtonSubmit" runat="server" CausesValidation="False" />

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900