Run javascript pageLoad function for partial postbacks

2 posts, 0 answers
  1. Igor
    Igor avatar
    10 posts
    Member since:
    Oct 2013

    Posted 11 Dec 2013 Link to this post

    I need to run some javascript code every time on page load, after Telerik Ajax controls are rendered on client. I tried to use this code:
    Sys.Application.add_load(SetFocusToField);

    function SetFocusToField() {
     
        if (indexToFocus == 0 && controlToFocus) {
            controlToFocus.focus();
            indexToFocus++;
        }
    }
    It works fine for the first time (regular page load) but on a partial postback this code doesn't run. I understand why it doesn't work but how can I call this javascript function on partial postbacks?

    I tried to use RegisterStartupScript but it doesn't work for me too :(

    string scriptFocus = @"
         
        ResetIndexOnFocus = 0;
        SetFocusToField();
     
    ";
    ScriptManager.RegisterStartupScript(this, this.GetType(), "scriptFocus", scriptFocus, true);


    Thank you in advance!
  2. msigman
    msigman avatar
    141 posts
    Member since:
    Apr 2008

    Posted 11 Dec 2013 Link to this post

    Hi Igor,

    You can use the OnRequestStart feature of the RadAjaxManager to execute JavaScript on every PostBack.  Give it a try and let us know how it works out.  http://www.telerik.com/help/aspnet-ajax/ajax-onrequeststart.html

    <script type="text/javascript">
        function requestStart(sender, eventArgs) {
            alert('Request start initiated by: ' + eventArgs.get_eventTarget());
        }
    </script>
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <ClientEvents OnRequestStart="requestStart" />
    </telerik:RadAjaxManager>

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top