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

RegisterStartupScript and more than one partial postbacks

1 Answer 41 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Igor
Top achievements
Rank 1
Igor asked on 01 Apr 2014, 07:35 AM
In BasePage class I overrided OnPreRender method:
    public class BaseMainPage : BaseDataPage
    {
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            if (!string.IsNullOrWhiteSpace(ExceptionHelper.MessageUI)) 
            {
                string script2run = @" $(window).load(function () { alert('" + ExceptionHelper.MessageUI + "'); }); ";

                // handle exception
                ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), script2run, true);

                // reset the message
                ExceptionHelper.MessageUI = null;
            }
        }
    }

This code displays alert message to user. The problem is when I have more than one partial postbacks the code doesn't work because once the method run then ExceptionHelper.MessageUI is null.

How can I solve the problem?


1 Answer, 1 is accepted

Sort by
0
Accepted
Eyup
Telerik team
answered on 04 Apr 2014, 07:43 AM
Hi Igor,

Please note that generally, Response.Write or direct script registering on ajax requests is not supported:
http://encosia.com/the-easiest-way-to-break-aspnet-ajax-pages/

You can check the the following sample for an alternative solution:
http://demos.telerik.com/aspnet-ajax/ajax/examples/common/recreatescripts/defaultcs.aspx

In addition, you can go through:
http://www.telerik.com/help/aspnet-ajax/ajax-error-handling.html

Hope this helps.

Regards,
Eyup
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.

 
Tags
Ajax
Asked by
Igor
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or