This is a migrated thread and some comments may be shown as answers.

Access RadScriptManager in Master Page from Content Page

1 Answer 645 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Atlas
Top achievements
Rank 1
Atlas asked on 09 Apr 2011, 01:50 AM
How do I access the Radscriptmanager located in my master page from my content page.

We have been having lots of problems with Response.Redirect because of Ajax Requests, and I found an article on your site that indicated that you should use RadAjaxManager.Redirect. To do so, I need to determine if the postback is an ajax postback, which I think is done like this:
scriptManager.IsInAsyncPostBack

But I can't figure out how to get to the script manager tag in the content page.

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandName.ToUpper() == "SELECT" || e.CommandName.ToUpper() == "SELECTNEWWINDOW")
    {
        GridDataItem item = RadGrid1.MasterTableView.Items[e.Item.ItemIndex];
        string encryptedVal = Cryptography.Encrypt(item["AssetNumber"].Text);
        if (e.CommandName.ToUpper() == "SELECT")
            Response.Redirect(string.Format("~/Client/Asset/?id={0}", encryptedVal));
        if (e.CommandName.ToUpper() == "SELECTNEWWINDOW")
            Helper.RedirectPage(Page, GetType(), string.Format("~/Client/Asset/?id={0}", encryptedVal), true);
    }
}

I am doing this right now, but would like to do this by using the RadAjaxManager.Redirect.
I am also using a RadAjaxManager Proxy, and don't see a redirect method for the proxy.

public static void RedirectPage(Page page, System.Type type, string url, bool openInNewWindow)
{
    string urlResolved = page.ResolveUrl(url);
    if (!openInNewWindow)
    {
        ScriptManager scriptManager = ScriptManager.GetCurrent(page);
        bool isPartialPagePostback = false;
        if (scriptManager != null && scriptManager.IsInAsyncPostBack)
            isPartialPagePostback = true;
        if (isPartialPagePostback)
            ScriptManager.RegisterStartupScript(page, type, "''", "window.location.href='" + urlResolved + "'",
                                                true);
        else
            HttpContext.Current.Response.Redirect(url);
    }
    else
    {
        ScriptManager.RegisterStartupScript(page, type, "''",
                                            "window.open('" + urlResolved +
                                            "', '', 'height=600,width=800,scrollbars=yes,resizable=yes,location=yes')",
                                            true);
    }
}

1 Answer, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 12 Apr 2011, 12:55 PM
Hello Nano,

In the same way you can get the current RadScriptManager by calling RadScriptManager.GetCurrent(Page), you get the current RadAjaxManager by calling RadAjaxManager.GetCurrent(Page).

I hope that helps.
Tags
Ajax
Asked by
Atlas
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Share this question
or