简体   繁体   English

如何从子页面关闭JQuery对话框

[英]How to close the JQuery Dialog Box from the child page

I am using JQuery and C#. 我正在使用JQuery和C#。

I am opening a JQuery Modal Dialog on the click of login link. 我在单击登录链接时打开一个JQuery Modal对话框。 Then I submit the complete form and form action is changed to my /login.aspx page, for a 15 seconds I am showing ajax processing image and on login.aspx page I validate the username and password entered by user. 然后,我提交完整的表单,并将表单操作更改为我的/login.aspx页面,持续15秒钟,我将显示ajax处理图像,并在login.aspx页面上,验证用户输入的用户名和密码。 There can be two scenario 可能有两种情况

1) User enters the valid username and password, in this case I am again redirecting back to same page from where the login link was clicked after validating on my /login.aspx page, this functionality is working fine as my current page is reloaded again. 1)用户输入有效的用户名和密码,在这种情况下,我在/login.aspx页面上进行验证后,将再次从单击登录链接的页面重定向回该页面,此功能可以正常工作,因为我的当前页面已重新加载。

2) however when user enters wrong username and password, I keep user on /login.aspx page (Please note I don't redirect back to the page from where user has clicked the login link). 2)但是,当用户输入错误的用户名和密码时,我会将用户保留在/login.aspx页面上(请注意,我不会重定向回用户单击登录链接的页面)。 Now Issue is that when user enter wrong username and password then /login.aspx comes, however if user in between clicks the browser back button then my Dialog box is shown open as I have set timeout for 15 secs. 现在的问题是,当用户输入错误的用户名和密码时,/ login.aspx就会出现,但是如果介于两者之间的用户单击浏览器后退按钮,则我的对话框将显示为打开,因为我已将超时时间设置为15秒。 I want to close the dailog box once user enters the wrong username and password. 一旦用户输入了错误的用户名和密码,我想关闭弹出对话框。

Below is the Jquery code where I am opening the dialog box. 下面是我打开对话框的Jquery代码。

 $('#skywardsLogin').dialog({
                        autoOpen: true,
                        width: 450,
                        modal: true,
                        title: $('.LoginpopupHeaderText').text()
                    });

And here I am trying to submit the form and changing the form action and also I am given timeout for 15 secs for showing the ajax processing image. 在这里,我尝试提交表单并更改表单操作,并且由于显示ajax处理图像而被给予15秒钟的超时时间。

$("#aspnetForm").attr("action", "http://localhost:8080/english/include/aspx/Login.aspx");
$("#aspnetForm").submit();
$('#divSuccessLogin').show();
// Wait for 15 seconds 
setTimeout(closeDialog, 15000); 

CloseDailog code is given below. 下面给出CloseDailog代码。

        function closeDialog()
        {
            $('#skywardsLogin').dialog("close"); 
}

I am struggling to close my dailog box as there is timeout for 15 secs to show the ajax processing image. 我正在努力关闭我的dailog框,因为超时了15秒才能显示ajax处理图像。 please suggest 请建议

I agree with Gidon it's a bit confusing. 我同意Gidon,这有点令人困惑。 But let's see if I understand you correctly, let's do it step by step. 但是,让我们看看我是否正确理解了我们,然后逐步进行。

  1. User comes to a page, let's say index.aspx. 用户进入页面,比方说index.aspx。
  2. User clicks a link that opens a dialog (using $().dialog() ) 用户单击打开对话框的链接(使用$().dialog()
  3. In the new dialog the user put's in their username/password. 在新对话框中,用户输入用户名/密码。
  4. When pressing a submit button you change en action of aspnetForm and submit the form. 当按下提交按钮时,您将更改aspnetForm的操作并提交表单。
  5. If the information is incorrect the user is still on login.aspx. 如果信息不正确,则用户仍在login.aspx上。
  6. User uses the browser's back-button 用户使用浏览器的后退按钮
  7. What happens? 怎么了?

It's the last part I don't quite understand. 这是我不太了解的最后一部分。 If the user clicks on the back button doesn't they end up on index.aspx? 如果用户单击“后退”按钮,他们最终不会进入index.aspx吗?

Also why the timer? 又为什么要计时器? There are no ajax calls? 没有ajax电话吗? $("#aspnetForm").submit(); submits the form as a normal html form or are you using something to override jQuery's standard .submit() 将表单提交为普通的html表单,或者您正在使用某些方法覆盖jQuery的标准.submit()

In any case if you want to invoke something after an ajax call is completed don't use a timer use: 无论如何,如果您想在ajax调用完成后调用某些东西,请不要使用计时器用法:

$(document).ajaxComplete(function() {
    $('#skywardsLogin').dialog("close"); 
});

Also it would be good if you could provide a link to the solution. 如果您可以提供该解决方案的链接,那也很好。

Are I'm on the right track? 我在正确的轨道上吗?

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

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