[英]how to close radwindow in asp.net?
I am a using ASP.NET controller to display user detail.我是一个使用 ASP.NET 控制器来显示用户详细信息的人。 When
RadWindow
is open & I tried to close with Close button.当
RadWindow
打开时,我尝试使用关闭按钮关闭。 But the problem is that after page load and post back it opens again and again.但问题是在页面加载和回发后,它一次又一次地打开。 I've multi-option on page: new, save, print etc. search.
我在页面上有多个选项:新建、保存、打印等。搜索。
<telerik:RadWindow ID="rwReport" runat="server" Behaviors="Close" KeepInScreenBounds="true"
AutoSize="true" VisibleOnPageLoad="false" Modal="true" Title="Report ACMI Advance Payment"
DestroyOnClose="true">
<ContentTemplate>
<ucRPV:ReportViewer id="ucReportViewer" runat="server" />
</ContentTemplate>
</telerik:RadWindow>
cs file code
private void Print()
{
try
{
// this.sADPs.DisplayReport();
Hashtable reportParameters = new Hashtable();
reportParameters.Add("DataSourceName", "dsACMIAdvancePayment");
reportParameters.Add("reportName", "rptACMIAdvancePayment.rdlc");
reportParameters.Add("Id", this.hfId.Value.ToString().ConvertTo<long>());
this.ucReportViewer.clearReport();
this.ucReportViewer.showReport(reportParameters);
this.rwReport.VisibleOnPageLoad = true;
//showReport(reportParameters);
}
catch(Exception e)
{
throw e;
}
}
ASPX code: ASPX 代码:
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="AjaxControlToolkit" %>
<%@ Register Src="../Reports/rpvReportViewerPopup.ascx" TagName="ReportViewer" TagPrefix="ucRPV" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Src="../Common/UserControls/ToolBarActions.ascx" TagName="ToolBarActions" TagPrefix="ucTBA" %>
</td>
Do not use the VisibleOnPageLoad property to show a RadWindow, register a script that will call its show() method.不要使用 VisibleOnPageLoad 属性来显示 RadWindow,注册一个将调用其 show() 方法的脚本。 Thus, subsequent postbacks will not cause it to show up by itself: http://www.telerik.com/help/aspnet-ajax/window-troubleshooting-opening-from-server.html .
因此,后续回发不会导致它自己显示: http : //www.telerik.com/help/aspnet-ajax/window-troubleshooting-opening-from-server.html 。
Of course, preventing the form from re-submitting as Felice suggested is another thing that may also be needed.当然,防止表单像 Felice 建议的那样重新提交是另一件可能也需要的事情。
To translate this into code:将此转换为代码:
instead of:代替:
this.rwReport.VisibleOnPageLoad = true;
use:用:
string script = "function f(){$find(\"" + rwReport.ClientID + "\").show(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
You can try below code : this might help-您可以尝试以下代码:这可能会有所帮助-
<telerik:RadScriptBlock runat="server" ID="scriptBlock">
<script type="text/javascript">
//<![CDATA[
function GetRadWindow() {
var oWindow = null;
if (window.radWindow) oWindow = window.radWindow;
else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
return oWindow;
}
function CloseWin() {
//Get the RadWindow
var oWindow = GetRadWindow();
//Call its Close() method
if (oWindow) {
oWindow.Close();
}
return false;
}
</script>
</telerik:RadScriptBlock>
And on Page: yourpage.aspx;... call the function onClientClick of button:在页面上: yourpage.aspx;... 调用按钮的 onClientClick 函数:
<asp:Button ID="btnClose" Text="Close" runat="server" CssClass="button" Enabled="true" OnClientClick="CloseWin();" />
I have experienced the same problem when you reload the page because the browser resend the information and the radwindow opens again.当您重新加载页面时,我遇到了同样的问题,因为浏览器重新发送信息并且 radwindow 再次打开。 To avoid such behavior I have adopted the following solution:
为了避免这种行为,我采用了以下解决方案:
Add a hidden filed to hold the client code:添加一个隐藏字段来保存客户端代码:
<asp:HiddenField runat="server" ID="_repostcheckcode" />
Add the following code in the code page:在代码页中添加以下代码:
protected void Page_Load(object sender, EventArgs e)
{
CancelUnexpectedRePost();
}
private void CancelUnexpectedRePost()
{
string clientCode = _repostcheckcode.Value;
//Get Server Code from session (Or Empty if null)
string serverCode = Session["_repostcheckcode"] as string ?? "";
if (!IsPostBack || clientCode.Equals(serverCode))
{
//Codes are equals - The action was initiated by the user
//Save new code (Can use simple counter instead Guid)
string code = Guid.NewGuid().ToString();
_repostcheckcode.Value = code;
Session["_repostcheckcode"] = code;
}
else
{
//Unexpected action - caused by F5 (Refresh) button
Response.Redirect(Request.Url.AbsoluteUri);
}
}
最近有类似的问题,发现这篇文章非常有用http://www.telerik.com/forums/opening-radwindow-from-the-server
Add a Button
with an OnClick
handler with the following code:使用以下代码添加一个带有
OnClick
处理程序的Button
:
protected void CloseRadWindow(object sender, EventArgs e)
{
rwReport.VisibleOnPageLoad = false;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.