1

i am new at ASP.NET and i got problem at using RegisterStartupScript. i have one page with two UserControl. each UserControl have GridView that can display Detail Page, just like this.

here's the portion of my code:

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);
        }
    }

My problem is when i click button at DetailView.aspx, ScriptManager.RegisterStartupScript((sender as Control), GetType(), "closeSender", "CloseAndRebindSender('navigate');", true); is not working, but ScriptManager.RegisterStartupScript((sender as Control), GetType(), "closeReceiver", "CloseAndRebindReceiver('navigate');", true); is working perfectly.

i have search on stackoverflow about why RegisterStartupScript is not working and found this question, but i didn't see something is wrong with my code.

is there anything i miss? Please help. Thank you

Community
  • 1
  • 1
abuybuy
  • 799
  • 2
  • 16
  • 33

2 Answers2

0

i've got the answer from this question. the problem is with the javascript in Sender.ascx. i don't know what's going on but i solved it.

Thank you

Community
  • 1
  • 1
abuybuy
  • 799
  • 2
  • 16
  • 33
0

Look into using the Sys.Application.Load event when working with IScriptControls, as accessing them in earlier client-side events will give you null. Here is an article on the matter: http://www.telerik.com/help/aspnet-ajax/window-troubleshooting-javascript-from-server-side.html.

rdmptn
  • 5,413
  • 1
  • 16
  • 29