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

Creating a RadScriptManager in cs

2 Answers 83 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Yoongu
Top achievements
Rank 1
Yoongu asked on 15 Oct 2014, 07:50 AM
Hi,

I have a question about RadScriptManager.

When I create a RadScriptManager to use the RadAjaxManager,
This works well if generated directly from the "aspx". 

aspx :
...
<
body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadButton1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" UpdatePanelCssClass="" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
        </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"></telerik:RadAjaxLoadingPanel>
    <telerik:RadButton ID="RadButton1" runat="server" OnClick="RadButton1_Click" Text="RadButton">
    </telerik:RadButton>
    <asp:Panel ID="Panel1" runat="server">
        <telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" Culture="ko-KR" Skin="Metro">
            <MasterTableView ClientDataKeyNames="itemcd" AllowAutomaticDeletes="False" AllowAutomaticInserts="False" AllowAutomaticUpdates="False" AutoGenerateColumns="False" DataKeyNames="itemcd" EditMode="Batch">
                <Columns>
                    <telerik:GridBoundColumn DataField="itemcd" FilterControlAltText="Filter itemcd column" HeaderText="품목코드" ReadOnly="True" SortExpression="itemcd" UniqueName="itemcd">
    <ColumnValidationSettings>
    <ModelErrorMessage Text=""></ModelErrorMessage>
    </ColumnValidationSettings>
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="itemnm" FilterControlAltText="Filter itemnm column" HeaderText="itemnm" SortExpression="itemnm" UniqueName="itemnm">
    <ColumnValidationSettings>
    <ModelErrorMessage Text=""></ModelErrorMessage>
    </ColumnValidationSettings>
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="size" FilterControlAltText="Filter size column" HeaderText="size" SortExpression="size" UniqueName="size">
    <ColumnValidationSettings>
    <ModelErrorMessage Text=""></ModelErrorMessage>
    </ColumnValidationSettings>
                    </telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
            <ClientSettings AllowKeyboardNavigation="true">
 
                <Selecting CellSelectionMode="MultiColumn"></Selecting>
                <ClientEvents OnCellSelected="RadGrid1_OnCellSelected" OnCellDeselecting="RadGrid1_OnCellDeselecting" OnBatchEditCellValueChanging="RadGrid1_OnBatchEditCellValueChanging" />
            </ClientSettings>
        </telerik:RadGrid>
    </asp:Panel>
    <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:DaeMyungDB %>"
        SelectCommand="SELECT top 1000 itemcd, itemnm, size FROM biitm01t"
        runat="server"></asp:SqlDataSource>
    </form>
</body>
...

However, I had to remove RadScriptManager from the aspx.
Then, When I add in cs this, RadAjaxManager does not work.

cs:
...
        protected void Page_Load(object sender, EventArgs e)
        {
            RadScriptManager scriptManager = new RadScriptManager();
 
            this.Form.Controls.Add(scriptManager);
        }
        protected void RadButton1_Click(object sender, EventArgs e)
        {
            RadGrid1.Rebind();
        }
...

What did I do wrong?

Thanks,
Yoongu.

2 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 17 Oct 2014, 11:12 AM
Hello Yoongu,

Thank you for contacting us.

To achieve the desired functionality you need to use following code snippet:
protected RadScriptManager theManager;
 
    protected override void OnPreInit(EventArgs e)
    {
        theManager = new RadScriptManager();
        Page.Items[typeof(ScriptManager)] = theManager;
        base.OnPreInit(e);
    }
 
    protected override void OnLoad(EventArgs e)
    {
        Page.Items[typeof(ScriptManager)] = null;
        this.Form.Controls.AddAt(0, theManager);
 
        base.OnLoad(e);
    }

Additionally I am sending you a simple example. Please check it out and let me know if it helps you.

If you need further assistance, do not hesitate to contact us again.

Regards,
Radoslav
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Yoongu
Top achievements
Rank 1
answered on 20 Oct 2014, 12:16 AM
Hi Radoslav,

Your answer was very helpful for me.

Thank you!
Tags
Ajax
Asked by
Yoongu
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Yoongu
Top achievements
Rank 1
Share this question
or