弹出asp.net页面,javascript和路径错误404

发布于 2024-12-05 12:49:24 字数 2142 浏览 1 评论 0原文

我有这个问题。两个页面:一个父页面和一个子页面,由 javascript 在弹出窗口中调用。 子页面是搜索页面。在此用户可以选择结果之一并通过查询字符串和 JavaScript 将其重新发送到父页面。

这是我用来在 search.aspx 的代码隐藏中执行此操作的脚本:

protected void Button4_Click(object sender, EventArgs e)
    {
        string url2 = "";

        if (GridView1.Rows.Count == 0)
        {
            string myStringVariable = string.Empty;
            myStringVariable = "Nessuna ricerca effettuata!";
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true);
        }
        else 
        {
            bool chk = false;

            foreach (GridViewRow row in GridView1.Rows)
            {
                RadioButton rad = (RadioButton)row.FindControl("RadioButton1");
                Label lb1 = (Label)row.FindControl("Label1");

                if (rad.Checked)
                {
                    chk = true;
                    url2 = "classmer.aspx?cod=" + lb1.Text;
                    break;
                }
            }
            if (chk)
            {
                StringBuilder st = new StringBuilder();
                st.Append("<script language='javascript'>");
                st.Append("window.opener.location = '" + url2 + "';");
                st.Append("self.close();");
                st.Append("</script>");
                ClientScript.RegisterStartupScript(typeof(Page), "", st.ToString());
            }
            else if (!chk)
            {
                string myStringVariable = string.Empty;
                myStringVariable = "Nessun mercato selezionato!";
                ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true);
            }
        }       

现在让我们讨论 404 错误。 父页面的网址为“http://localhost/App/ClassMer/classmer.aspx” 子页面具有此 url“http://localhost/App/ClassMer/search.aspx”

通过单击搜索页面上的确认按钮, ,它会绕过该 url“http://localhost/ClassMer/classmer.aspx”重新发送“App”文件夹(这是部署应用程序时在 IIS7 中创建的虚拟路径。)

如何解决此问题?

我尝试了一些解决方案,例如添加 Request.ApplicationPath 或直接通过字符串指定我传递给 javascript 的 url 路径,但没有发生。

请帮助!

谢谢

I've this problem. Two pages: a parent and a child called in popup window by javascript.
The child page is a search page. In this user can select one of the results and resend it to the parent page by querystring and javascript.

this is the script I use to do this in codebehind of search.aspx:

protected void Button4_Click(object sender, EventArgs e)
    {
        string url2 = "";

        if (GridView1.Rows.Count == 0)
        {
            string myStringVariable = string.Empty;
            myStringVariable = "Nessuna ricerca effettuata!";
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true);
        }
        else 
        {
            bool chk = false;

            foreach (GridViewRow row in GridView1.Rows)
            {
                RadioButton rad = (RadioButton)row.FindControl("RadioButton1");
                Label lb1 = (Label)row.FindControl("Label1");

                if (rad.Checked)
                {
                    chk = true;
                    url2 = "classmer.aspx?cod=" + lb1.Text;
                    break;
                }
            }
            if (chk)
            {
                StringBuilder st = new StringBuilder();
                st.Append("<script language='javascript'>");
                st.Append("window.opener.location = '" + url2 + "';");
                st.Append("self.close();");
                st.Append("</script>");
                ClientScript.RegisterStartupScript(typeof(Page), "", st.ToString());
            }
            else if (!chk)
            {
                string myStringVariable = string.Empty;
                myStringVariable = "Nessun mercato selezionato!";
                ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true);
            }
        }       

now let's pass to the 404 error.
the parent page has this url "http://localhost/App/ClassMer/classmer.aspx"
the child page has this url "http://localhost/App/ClassMer/search.aspx"

by clicking the confirm button on search page, it resend to this url "http://localhost/ClassMer/classmer.aspx" bypassing the "App" folder (that is a virtal path created in IIS7 when deploying the application.)

how can I resolve this?

I tried some solution like adding Request.ApplicationPath or directly specifing by string the path to the url I pass to javascript but none happened.

Help, please!!

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淑女气质 2024-12-12 12:49:24

我想 Request.ApplicationPath 应该没问题。请尝试以下操作:

url2 = HttpRuntime.AppDomainAppVirtualPath + "/classmer.aspx?cod=" + lb1.Text;

Request.ApplicationPath should be fine I'd have thought. Try the following:

url2 = HttpRuntime.AppDomainAppVirtualPath + "/classmer.aspx?cod=" + lb1.Text;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文