RegisterStartupScript is not working

本文关键字:working not is RegisterStartupScript | 更新日期: 2023-09-27 17:50:41

我是ASP的新手。. NET和我在使用RegisterStartupScript时遇到了问题。我有一个页面与两个UserControl。每个UserControl都有GridView,可以显示Detail Page,就像这样。

这是我的代码部分:

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不工作,发现了这个问题,但我没有看到我的代码有问题。

有什么我错过的吗?请帮助。谢谢你

RegisterStartupScript is not working

我已经从这个问题中得到了答案。问题是在Sender.ascx的javascript。我不知道怎么回事,但我解决了。

谢谢

在使用IScriptControls时考虑使用Sys.Application.Load事件,因为在早期的客户端事件中访问它们将给您null。这里有一篇关于此事的文章:http://www.telerik.com/help/aspnet-ajax/window-troubleshooting-javascript-from-server-side.html.