Click here to Skip to main content
15,908,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a message that pops up when the user clicks the save button but it will not display. My other code displays fine but the one for the save button does not.

Here is the code that works:
C#
if (Page.IsValid)
            {
                ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You have successfully submitted the electronic portion of the General and Enrollment Profile.  Please send your signed Profile along with any required attachments to SACSCOC, Attn: Profiles, 1866 Southern Lane, Decatur, Ga 30033.');location.href='WelcomeMenu.aspx';", true);
            }


Here is the code that does not work:
C#
if (Page.IsValid)
            {
                SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
                con2.Open();
                SqlCommand level = new SqlCommand("select accessLevel, User_ID from Table99 where User_ID = @INST_ID AND accessLevel = @accessLevel", con2);
                level.Parameters.Add(new SqlParameter("INST_ID", TextBoxINST_ID.Text));
                level.Parameters.Add(new SqlParameter("accessLevel", TextBoxaccessLevel.Text));

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

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

                    if (returnedLevel == 1)
                    {
                        
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Submitted the Cohort. If you have Additional Cohorts, Please Click on the Graduation Rate Link to Enter another Cohort');location.href='WelcomeMenu.aspx';", true);
                    }
                    else if (returnedLevel == 2)
                    {
                        
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Submitted the Cohort. If you have Additional Cohorts, Please Click on the Graduation Rate Link to Enter another Cohort');location.href='WelcomeMenu.aspx';", true);
                    }
                    else if (returnedLevel == 3)
                    {
                        
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Submitted the Cohort. If you have Additional Cohorts, Please Click on the Graduation Rate Link to Enter another Cohort');location.href='WelcomeMenu.aspx';", true);
                    }
                    else if (returnedLevel == 11)
                    {
                        
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Submitted the Cohort. If you have Additional Cohorts, Please Click on the Graduation Rate Link to Enter another Cohort');location.href='WelcomeMenu.aspx';", true);
                    }
                    else if (returnedLevel == 21)
                    {
                        
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Submitted the Cohort. If you have Additional Cohorts, Please Click on the Graduation Rate Link to Enter another Cohort');location.href='WelcomeMenu.aspx';", true);
                    }
                    else if (returnedLevel == 31)
                    {
                        
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Submitted the Cohort. If you have Additional Cohorts, Please Click on the Graduation Rate Link to Enter another Cohort');location.href='WelcomeMenu.aspx';", true);
                    }
                    else if (returnedLevel == 7)
                    {
                        
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Submitted the Cohort. If you have Additional Cohorts, Please Click on the Graduation Rate Link to Enter another Cohort');location.href='CEOPage.aspx';", true);
                    }
                }
                con2.Close();


What did I do wrong?
Posted

Although I am not sure but, I noticed that you have used series if..else if..else if.. statements. Are you sure that the value of "returnedLevel" will always be between 1,2,3,11,21,31 & 7? May be you are missing a simple else statement at the last of this "if..else if..else if..." chain.

May be something like

C#
else{
                        
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('Something went wrong. Please try again !');", true);
                    }


Please reply if this doesn't solve your problem.
 
Share this answer
 
v2
Comments
Computer Wiz99 29-Oct-14 15:04pm    
Sorry about that but I took the If Else statement out. Thinking that was why it was not working but no. It works on my other projects.
Tente usar o tipo do script!!

C#
ScriptManager.RegisterStartupScript(Page, GetType(), Guid.NewGuid().ToString(), "javascript:alert('You Have Successfully Submitted the Cohort. If you have Additional Cohorts, Please Click on the Graduation Rate Link to Enter another Cohort'); window.location.href='WelcomeMenu.aspx';", true);
 
Share this answer
 
Comments
Computer Wiz99 29-Oct-14 15:02pm    
Is there a way to add an ok button and cancel button. Ok button will redirect to another page and the cancel will let the user stay on the current page.

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