我使用ASP.NET控制器来显示用户详细信息。 RadWindow
开放时&我试图用关闭按钮关闭。但问题是,在页面加载和回发后,它会一次又一次地打开。我在页面上有多个选项:新建,保存,打印等搜索。
<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代码:
<%@ 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>
答案 0 :(得分:0)
您可以尝试以下代码:这可能会有所帮助 -
<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>
在页面上:yourpage.aspx; ...调用onClientClick函数按钮:
<asp:Button ID="btnClose" Text="Close" runat="server" CssClass="button" Enabled="true" OnClientClick="CloseWin();" />
答案 1 :(得分:0)
我在重新加载页面时遇到了同样的问题,因为浏览器会重新发送信息并再次打开radwindow。为了避免这种行为,我采用了以下解决方案:
添加隐藏字段以保存客户端代码:
<asp:HiddenField runat="server" ID="_repostcheckcode" />
在代码页中添加以下代码:
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);
}
}
可以找到原始文章here。
答案 2 :(得分:0)
不要使用VisibleOnPageLoad属性来显示RadWindow,注册一个将调用其show()方法的脚本。因此,后续回发不会使其自行显示:http://www.telerik.com/help/aspnet-ajax/window-troubleshooting-opening-from-server.html。
当然,如Felice建议的那样阻止表格重新提交是另一件可能需要的事情。
将其转换为代码:
而不是:
this.rwReport.VisibleOnPageLoad = true;
使用:
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);
答案 3 :(得分:0)
最近遇到类似的问题,发现这篇文章非常有用http://www.telerik.com/forums/opening-radwindow-from-the-server
答案 4 :(得分:0)
使用以下代码添加带有 Button
处理程序的 OnClick
:
protected void CloseRadWindow(object sender, EventArgs e)
{
rwReport.VisibleOnPageLoad = false;
}