在 asp.net 和 vb.net web 应用程序中保存后如何关闭弹出窗体
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24301856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to close a popup form after saving in asp.net and vb.net web application
提问by Bashabi
I am new with asp.net and vb.net.
我是 asp.net 和 vb.net 的新手。
I am maintaining a web application which contains many users and their information. From the list.aspx page if some one clicks any individual name from the list it goes to another page called update_status.aspx which contains the information of a particular user. This page produces a form where we can update the information about that user by clicking update button in that form. After clicking the update button it saves the update and redicets to details.aspx page.
我正在维护一个包含许多用户及其信息的 Web 应用程序。从 list.aspx 页面,如果有人单击列表中的任何个人名称,它会转到另一个名为 update_status.aspx 的页面,其中包含特定用户的信息。此页面生成一个表单,我们可以通过单击该表单中的更新按钮来更新有关该用户的信息。单击更新按钮后,它会将更新和 redicets 保存到 details.aspx 页面。
Now this update_status.aspx page is converted into a popup page and renamed as update_status_popup.aspx
现在这个update_status.aspx页面被转换成一个弹出页面并重命名为update_status_popup.aspx
Now the requirement is to close the popup window after update when someone clicks update and dont redirect to details.aspx page
现在要求是当有人点击更新时关闭更新后的弹出窗口,不要重定向到 details.aspx 页面
How can I do that. The webpage is built with asp.net and vb.net
我怎样才能做到这一点。该网页是用asp.net和vb.net构建的
I am including the codes below.
我包括下面的代码。
The following link opens the popup window called Update_status_popup.aspx
以下链接打开名为 Update_status_popup.aspx 的弹出窗口
<a class="hover-glow" style="cursor:pointer;" data-placement="bottom" rel="tooltip" title="change status" data-bind="click: $parent.openPopup"><i class="icon icon-random"></i> </a>
In the update_staus_popup.aspx the code for the update button is
在 update_staus_popup.aspx 中,更新按钮的代码是
<div class="btn-wrapper">
<button runat="server" id="btnUpdate" class="btn" data-bind="enable: ((statusId() == 10 && offeredSalary() < 0) || (statusId() == 11 && finalSalary() < 0) || (feeType() == 2 && introductionFee() <= 0 && statusId() == 11 && agencyApp() == 'True')) ? false : true">Update</button>
<a class="btn" href="javascript:window.close();">Close</a>
</div>
there are two button UPDATE and CLOSE. Close button also closes the window but the client requires to close the form automatically after updating.
有两个按钮 UPDATE 和 CLOSE。关闭按钮也会关闭窗口,但客户端需要在更新后自动关闭表单。
the present VB.net code for btnUPDATE is as follow
btnUPDATE 的当前 VB.net 代码如下
Protected Sub btnUpdate_ServerClick(sender As Object, e As EventArgs) Handles btnUpdate.ServerClick
If comNewStatus.Items.Count <= 0 Then
Response.Redirect("details.aspx?i=" & Request("i"))
End If
Dim previusStatus = VacancyApplication.Status, _
newStatus = CInt(comNewStatus.Value)
If newStatus <> VacancyApplication.StatusID Then
Try
If newStatus = 10 Then
VacancyApplication.OfferedSalary = CType(txtOfferedSalary.Value, Decimal)
VacancyApplication.AddNote("Offered: " & txtOfferedSalary.Value)
ElseIf newStatus = 11 Then
VacancyApplication.AddNote("Final salary: " & txtFinalSalary.Value)
Vacancy.FinalSalary = CDec(txtFinalSalary.Value)
Vacancy.Save()
If Vacancy.FeeType = 1 AndAlso CDec(txtFinalSalary.Value) > 0 Then
Vacancy.CalculateFees()
Vacancy.SaveFees()
End If
Dim vh As New VacancyHistory With {.VacancyID = VacancyApplication.VacancyID, .Description = "Final salary added. Amount:" & txtFinalSalary.Value}
vh.Save()
ElseIf newStatus = 12 Then
VacancyApplication.StartDate = CDate(txtStartDate.Value)
VacancyApplication.AddNote("Start date: " & txtStartDate.Value)
End If
If Vacancy.FeeType = 2 AndAlso CDec(txtFinalIntroductionFee.Value) Then
Vacancy.SetFinalIntroductionFee(CDec(txtFinalIntroductionFee.Value))
Dim vh As New VacancyHistory With {.VacancyID = VacancyApplication.VacancyID, .Description = "Introduction fee added as per variable fee type. Fee:" & txtFinalIntroductionFee.Value}
vh.Save()
End If
VacancyApplication.Save()
VacancyApplication.UpdateStatus(CInt(comNewStatus.Value), True, False)
Catch ex As Exception
_logger.Fatal(ex.Message)
Response.Redirect("/E4/Error/500.aspx")
End Try
If Not String.IsNullOrWhiteSpace(txtNote.Value) Then VacancyApplication.AddNote(txtNote.Value.Trim())
_logger.Fatal("details.aspx?i=" & VacancyApplication.ID & "&c=" & VacancyApplication.StatusID)
End If
Response.Redirect("details.aspx?i=" & VacancyApplication.ID & "&c=" & VacancyApplication.StatusID)
End Sub
End Class
The above code redirects the page to details.aspx page (which also opens in the same popupup and does not look smart.). Please suggest me with the code which will close the update_status_popup.aspx page after saving the details.
上面的代码将页面重定向到 details.aspx 页面(它也在同一个弹出窗口中打开,看起来并不智能。)。请建议我保存详细信息后将关闭 update_status_popup.aspx 页面的代码。
回答by James Thorpe
You can use RegisterClientScriptBlock
您可以使用RegisterClientScriptBlock
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(),"CloseWindowScript","window.close();",True)
Use this in place of Response.Redirect; it will inject the call to window.close() when the page reloads, causing the window to close.
用它代替Response.Redirect; 它会在页面重新加载时注入对 window.close() 的调用,从而导致窗口关闭。

