RegisterStartupScript不起作用

时间:2015-05-25 05:02:00

标签: javascript c# asp.net telerik

我是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,但我没有看到我的代码出错。

有什么我想念的吗? 请帮忙。谢谢

2 个答案:

答案 0 :(得分:0)

我已经得到了question的答案。 问题出在Sender.ascx中的javascript。 我不知道发生了什么,但我解决了。

谢谢

答案 1 :(得分:0)

在使用IScriptControls时,请查看使用Sys.Application.Load事件,因为在早期客户端事件中访问它们会给出null。以下是关于此事的文章:http://www.telerik.com/help/aspnet-ajax/window-troubleshooting-javascript-from-server-side.html