我是ASP.NET的新手,我在使用RegisterStartupScript时遇到了问题。我有一个带有两个UserControl的页面。每个UserControl都有可以显示详细页的GridView,就像this一样。
下面是我的代码的一部分:
SenderUserControl.ascx
<script type="text/javascript">
function ShowInsertFormSender() {
window.radopen("WebfrmManageMemo.aspx?RefType=S", "UserListDialog");
return false;
}
function refreshGridSender(arg) {
if (!arg) {
$find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("RebindSender");
}
else {
$find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("RebindAndNavigateSender");
}
}
function RowDblClickReceiver(sender, eventArgs) {
window.radopen("WebfrmManageMemo.aspx?RefType=S&MemoID=" + eventArgs.getDataKeyValue("MemoID"), "UserListDialog");
}
ReceiverUserControl.ascx
<script type="text/javascript">
function ShowInsertFormReceiver() {
window.radopen("WebfrmManageMemo.aspx?RefType=R", "UserListDialog");
return false;
}
function refreshGridReceiver(arg) {
if (!arg) {
$find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("RebindReceiverReferral");
}
else {
$find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("RebindAndNavigateReceiverReferral");
}
}
function RowDblClickReceiver(sender, eventArgs) {
window.radopen("WebfrmManageMemo.aspx?RefType=R&MemoID=" + eventArgs.getDataKeyValue("MemoID"), "UserListDialog");
}
DetailView.aspx
<script type="text/javascript">
function CloseAndRebindSender(args) {
GetRadWindow().BrowserWindow.refreshGridSender(args);
GetRadWindow().close();
}
function CloseAndRebindReceiver(args) {
GetRadWindow().BrowserWindow.refreshGridReceiver(args);
GetRadWindow().close();
}
function GetRadWindow() {
var oWindow = null;
if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz as well)
return oWindow;
}
function CancelEdit() {
GetRadWindow().close();
}
</script>DetailView.aspx.cs
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Request["RefType"].ToString() == "S")
{
ScriptManager.RegisterStartupScript((sender as Control), GetType(), "closeSender", "CloseAndRebindSender('navigate');", true);
}
else if (Request["RefType"].ToString() == "R")
{
ScriptManager.RegisterStartupScript((sender as Control), GetType(), "closeReceiver", "CloseAndRebindReceiver('navigate');", true);
}
}我的问题是,当我在DetailView.aspx上点击按钮时,ScriptManager.RegisterStartupScript((sender as Control), GetType(), "closeSender", "CloseAndRebindSender('navigate');", true);不工作,但ScriptManager.RegisterStartupScript((sender as Control), GetType(), "closeReceiver", "CloseAndRebindReceiver('navigate');", true);工作得很好。
我在stackoverflow上搜索了RegisterStartupScript不工作的原因,找到了这个question,但我没有看到我的代码有什么问题。
有什么我错过的吗?请帮帮忙。谢谢
发布于 2015-05-25 14:09:13
我已经从这个question中得到了答案。问题出在Sender.ascx中的javascript。我不知道发生了什么,但我解决了。
谢谢
发布于 2015-05-26 19:19:32
在使用IScriptControls时,请考虑使用Sys.Application.Load事件,因为在以前的客户端事件中访问它们会得到null。这里有一篇关于这个问题的文章:http://www.telerik.com/help/aspnet-ajax/window-troubleshooting-javascript-from-server-side.html。
https://stackoverflow.com/questions/30431508
复制相似问题