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

Run javascript pageLoad function for partial postbacks

1 Answer 519 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Igor
Top achievements
Rank 1
Igor asked on 11 Dec 2013, 01:05 PM
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!

1 Answer, 1 is accepted

Sort by
0
msigman
Top achievements
Rank 2
answered on 11 Dec 2013, 08:54 PM

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>

Tags
Ajax
Asked by
Igor
Top achievements
Rank 1
Answers by
msigman
Top achievements
Rank 2
Share this question
or