views:

149

answers:

1

hi my dear friends:

The pages on my project are base on master and content pages...

I want to do something with javascript(rather than jquery) in one of content pages after ALL OF MASTER AND CONTENT ELEMENTS ARE LOADED COMPLETELY.(for example set focus on a RadComboBox Control)

For doing that I used the below code :

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

    <script src="../JQuery/jquery-1.4.1.js" language="javascript" type="text/javascript"></script>


    <script type="text/javascript">

        onload = onloadOfDocument;

        function onloadOfDocument() {

            var combo = $find("<%= RadcbPersonelCompleteNameInvwNoskhehEdit.ClientID %>");
            alert(combo);
            var comboInput = combo.get_inputDomElement();
            comboInput.focus();
        }

    </script>
</asp:Content>

But alert(combo); always returns null.(the $find code is for telerik controls and the upper codes about telerik controls are completely true)

To solve this null problem I test the ways shown below:

1- I Removed all of controls from master and content page except RadComboBox Control and null problem disappeared , so i derived the null peoblem is about all of elements of master and content page have not been loaded when

$find("<%= RadcbPersonelCompleteNameInvwNoskhehEdit.ClientID %>");

is fired.

2- so i used

$(document).ready(function() { my codes });

instead of

onload = onloadOfDocument;

but problem not solved - i do not know why!!!

3- at last i test the below code and it works perfectly :

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

<script src="../JQuery/jquery-1.4.1.js" language="javascript" type="text/javascript"></script>


<script type="text/javascript">

    //onload = onloadOfDocument;
      document.onkeyup = onkeyupOfDocument;

    function onkeyupOfDocument() {

        var combo = $find("<%= RadcbPersonelCompleteNameInvwNoskhehEdit.ClientID %>");
        alert(combo);
        var comboInput = combo.get_inputDomElement();
        comboInput.focus();
    }

</script>

What function of document should i use for doing some javascript codes after all Of MASTER AND CONTENT ELEMENTS are loaded completely?

Thanks in future advance

A: 

Wouldn't it be:

var combo=$("#<%= RadcbPersonelCompleteNameInvwNoskhehEdit.ClientID %>")[0];

?

(Assuming that RadcbPersonelCompleteNameInvwNoskhehEdit.ClientID resolves to the id attribute of an element in the DOM)

spender
That's what I would've thought the issue is too.The easiest way to check if $(document).ready(function(){ }); is working is to add an alert... and then to add the code that you want run in there.It gives a simple and clean way to determine whether jQuery is being loaded.
PieterG
var combo=$("#<%= RadcbPersonelCompleteNameInvwNoskhehEdit.ClientID %>")[0];-> this syntax is incorrect...=============i test $(document).ready(function(){ }); with alert and alert works fine - but $find still returns null...
LostLord
Umm. Why is it incorrect? What are you trying to do? Get the element with ID RadcbPersonelCompleteNameInvwNoskhehEdit.ClientID, or did I misunderstand? I've never seen $find before.
spender
the syntax of upper codes (about telerik controls) at my question are true -> refer to #3th test...it seems problem is about $(document).ready(function(){ }); but i test it with an alert and alert works fine - i do not know what is going on about document.ready!
LostLord