警报消息重定向问题 [英] Alert Message redirect issue

查看:70
本文介绍了警报消息重定向问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个警报重定向问题。当用户单击提交时,将显示警报消息。如果用户单击确定,则页面将重新加载,用户可以输入另一个页面。如果用户单击取消,则应使用我所具有的重定向代码重定向页面。如何使用我的重定向代码让重定向工作在警报消息上?



I have an alert redirect issue. When the user click on submit the alert message displays. If the user clicks on Ok the page will reload and the user can enter another one. If the user clicks Cancel the page should redirect using the redirect code I have in place. How can I get the redirect to work on the alert message with the redirect code I have?

if (Page.IsValid)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "if(confirm('You Have Successfully Submitted the Cohort! Do you have Additional Cohorts Please Click Yes to Enter another Cohorts? If you are finished entering Cohorts, Please click No.') == false){ window.location();}else{window.location.href='Gradrate.aspx';}", true);
            }
            else
            {
                SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
                con2.Open();
                SqlCommand level = new SqlCommand("select accessLevel, INST_ID from Table99 where INST_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)
                    {
                        Response.Redirect("FormAPublic.aspx");
                    }
                    else if (returnedLevel == 2)
                    {
                        Response.Redirect("FormCPrivateNon.aspx");
                    }
                    else if (returnedLevel == 3)
                    {
                        Response.Redirect("FormDPrivateFor.aspx");
                    }
                    else if (returnedLevel == 11)
                    {
                        Response.Redirect("FormAPublicL.aspx");
                    }
                    else if (returnedLevel == 21)
                    {
                        Response.Redirect("FormCPrivateNonL.aspx");
                    }
                    else if (returnedLevel == 31)
                    {
                        Response.Redirect("FormDPrivateForL.aspx");
                    }
                    else if (returnedLevel == 7)
                    {
                        Response.Redirect("CEOPage.aspx");
                    }
                }
                con2.Close();

推荐答案

Quote:

Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "if(confirm('You Have Successfully Submitted the Cohort! Do you have Additional Cohorts Please Click Yes to Enter another Cohorts? If you are finished entering Cohorts, Please click No.') == false){ window.location();}else{window.location.href='Gradrate.aspx';}", true);

当您点击时, Developer Tool 控制台选项卡中显示问题取消

这是因为我强调的代码。



你应该这样做。 ..

Currently it is showing issue in Console Tab of Developer Tool, when you click on "Cancel".
And that is because of the Code I have underlined.

You should do like...

Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "if(confirm('You Have Successfully Submitted the Cohort! Do you have Additional Cohorts Please Click Yes to Enter another Cohorts? If you are finished entering Cohorts, Please click No.') == false){ window.location.href='someOtherPage.aspx';}else{window.location.href='Gradrate.aspx';}", true);



所以,使用 window.location.href 并在其他部分中为确定按钮。


哦。你的代码暗示只有当页面无效时才会使用重定向if语句。你应该将你的页面重定向代码移动到另一个方法喜欢



Oh. Well your code implies that the redirect if statements will be used only if page is not valid. You should move your page redirect code to another method like

public string GetRedirect()
{
string redirect = "";
SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
                con2.Open();
                SqlCommand level = new SqlCommand("select accessLevel, INST_ID from Table99 where INST_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)
                    {
                        redirect = "FormAPublic.aspx";
                    }
                    else if (returnedLevel == 2)
                    {
                        redirect = "FormCPrivateNon.aspx";
                    }
                    else if (returnedLevel == 3)
                    {
                        redirect = "FormDPrivateFor.aspx";
                    }
                    else if (returnedLevel == 11)
                    {
                        redirect = "FormAPublicL.aspx";
                    }
                    else if (returnedLevel == 21)
                    {
                        redirect = "FormCPrivateNonL.aspx";
                    }
                    else if (returnedLevel == 31)
                    {
                        redirect = "FormDPrivateForL.aspx";
                    }
                    else if (returnedLevel == 7)
                    {
                        redirect = "CEOPage.aspx";
                    }
                }
                con2.Close();
return redirect; 
}





然后在你的javascript代码位:



Then in your javascript code bit:

Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "if(confirm('You Have Successfully Submitted the Cohort! Do you have Additional Cohorts Please Click Yes to Enter another Cohorts? If you are finished entering Cohorts, Please click No.') == false){ window.location.href=" + GetRedirect() + /*<-Sorry this should be in string concat format*/";}else{window.location.href='Gradrate.aspx';}", true);





那么你的foraech循环不需要成为一个循环。我假设,你说不然,dt1.Rows.Count是1?



By the way, your foraech loop doesn't need to be a loop. I'm assuming, you tell otherwise, that dt1.Rows.Count is 1?


这篇关于警报消息重定向问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆