简体   繁体   English

Facebox Jquery框的“关闭”按钮关闭母版页,而不弹出

[英]Close button to Facebox Jquery box closes master page, not popup

I am using the Facebox jquery box to load a little form with a Submit Button and a Cancel Button. 我正在使用Facebox jQuery框来加载带有“提交”按钮和“取消”按钮的小表格。

When I click Submit it closes the Main page that loaded the Facebox window instead of the Facebox window! 当我单击“提交”时,它将关闭加载Facebox窗口而不是Facebox窗口的主页! It leaves the AddNote.aspx site open (which is loaded by Facebox) and closes my Main.aspx. 它使AddNote.aspx站点处于打开状态(由Facebox加载),并关闭我的Main.aspx。

Here is my code behind in AddNote.aspx (Which is rendered by the Facebox popup on Main.aspx): 这是我在AddNote.aspx中的代码(由Main.aspx上的Facebox弹出窗口呈现):

    protected void SubmitButtom_Click(object sender, EventArgs e)
    {

        string note = NotesTextBox.Text;

        //will need to add current user

        using (cmd = new SqlCommand("INSERT INTO notes (FID, note_date, note_text) VALUES (@FID, @note_date, @note_text)", con))
        {
            con.Open();
            cmd.Parameters.Add(new SqlParameter("FID", FID));
            cmd.Parameters.Add(new SqlParameter("note_date", DateTime.Now.ToString()));
            cmd.Parameters.Add(new SqlParameter("note_text", note));
            cmd.ExecuteNonQuery();
            con.Close();
            Page.ClientScript.RegisterOnSubmitStatement(typeof(Page), "closeModal", "$.facebox.close();");              //WHY DOES THIS CLOSE MAIN.ASPX INSTEAD OF FACEBOX WINDOW?                  
        }           

    }

Welcome to ASP.NET 欢迎使用ASP.NET

You're using server-side code to process this form. 您正在使用服务器端代码来处理此表单。 That means you have to do what ASP.NET terms a "PostBack". 这意味着您必须执行ASP.NET所谓的“ PostBack”。 What this means is that the form on the page is submitting data back to itself for processing. 这意味着页面上的form正在将数据提交回自身进行处理。 Since the "submit" button was the button that triggered it, your handler gets called. 由于“提交”按钮是触发它的按钮,因此将调用您的处理程序。

The important thing here is that this requires a trip to the server. 这里重要的是,这需要访问服务器。 The form is being submitted, which in normal HTTP (and thus in ASP.NET, as it is a framework built for HTTP processing), means a page refresh. 提交表单,在常规HTTP中(因此在ASP.NET中,因为它是为HTTP处理而构建的框架),这意味着页面刷新。 The browser says "Oh! The form is being submitted! Time to make a request to the server, and wait for a response. I can probably unload the page I have right now." 浏览器说:“哦!正在提交表单!是时候向服务器发送请求了,等待响应。我可能可以卸载当前拥有的页面。” So it does. 确实如此。

In order to do what you want, look into "AJAX", or Asynchronous XMLHttpRequest. 为了执行您想要的操作,请查看“ AJAX”或异步XMLHttpRequest。 They're the same thing, except that one is more buzz-wordy. 他们是同一回事,除了一个更嗡嗡声。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM