$find not working with IE 8

11 posts, 0 answers
  1. taeho
    taeho avatar
    29 posts
    Member since:
    Mar 2008

    Posted 11 Dec 2009 Link to this post

    Hi,

    I am trying to reference a radTextBox through javascript to capitalize its value on blur and keypress event.
    However, $find(client-Side-Object-Name) returns null in IE whereas it works fine in firefox (3.5.5).

    The version of our telerik is 2008.3.1314.35

    <telerik:RadScriptBlock ID="radScriptBlock" runat="server"
        <script type="text/javascript"
     
            AddPageLoadHandler(function() 
            { 
                AutoCapitaliseFirstChar('<%= FirstNameTextBox.ClientID %>'); 
            }); 
             
        </script> 
        </telerik:RadScriptBlock> 
    function AddPageLoadHandler(fn) 
        Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(fn); 
    // not created dynamically 
    <telerik:RadTextBox runat="server" ID="FirstNameTextBox" /> 
    // These client-side functions auto-capitalises text in RadTextBox as user enters it 
    // The conversion is done after a short timeout to avoid interfering with normal onfocus behaviour 
    function AutoCapitaliseFirstChar(radTextBoxClientId) { 
     
        var radTextBoxClientObject = $find(radTextBoxClientId); 
        // here radTextBoxClientObject is null for IE but not for firefox 
        // so it works fine with firefox not with IE 8 
     
        // This converts the text when field loses focus 
        $(radTextBoxClientObject.get_element()).blur(function() { 
            setTimeout(function() { 
                var val = radTextBoxClientObject.get_value(); 
                radTextBoxClientObject.set_value(val.substring(0, 1).toUpperCase() + val.substring(1)) 
            }, 200); 
        }); 
     
        // Except in Safari, convert the text as it is typed 
        // (in Safari this is incompatible with the field autocomplete behaviour) 
        if (!$.browser.safari) { 
            $(radTextBoxClientObject._textBoxElement).keypress(function() { 
                setTimeout(function() { 
                    var val = $(radTextBoxClientObject._textBoxElement).val(); 
                    radTextBoxClientObject.set_value(val.substring(0, 1).toUpperCase() + val.substring(1)) 
                }, 200); 
            }); 
        } 
    Any ideas would be appreciated,

    regards,

    Toby


  2. Dimo
    Admin
    Dimo avatar
    8332 posts

    Posted 14 Dec 2009 Link to this post

    Hello Toby,

    If $find doesn't work, this generally means that:

    1) The ID does not exist
    2) There is no client control instance attached to the ID
    3) $find() is executed before the client control instance has been initialized

    In your case the problem is (3). Please use

    Sys.Application.add_load(...);

    instead of

    Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(...);


    All the best,
    Dimo
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jose Granja
    Jose Granja avatar
    84 posts
    Member since:
    Oct 2009

    Posted 09 Feb 2010 Link to this post

    Hi! I have a similar problem but my context is diferent!

    on the page_load event I do a:

    alert($find('RadEditorClientID'));

    the page, I don't understand why, reloads twice. The first time the alert returns me an object and the second time it returns me nulls :S I don't now what causes the reload, I set de AutoEventWireup="False" and the in the code behind is defined as follows:

     this.Load += new EventHandler(Page_Load);

    protected void Page_Load(object sender, EventArgs e)

    I don't know what causing the problem. In IE it reloads twice also but the $find works fine all the time!

    I'm using RadControls for ASP.NET AJAX Q3 2009

    Can you please help me out?

    cheers







  5. Dimo
    Admin
    Dimo avatar
    8332 posts

    Posted 09 Feb 2010 Link to this post

    Hi Jose,

    I am afraid the provided information is insufficient. Please provide a demo.

    Sincerely yours,
    Dimo
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
  6. Justin
    Justin avatar
    4 posts
    Member since:
    Aug 2008

    Posted 11 Feb 2010 Link to this post

    Good day Dimo,

    You are probably tired of having to hear about IE issues but I am experiencing the same problem as below but I hope mine has a simpler solution.  Everything works in FF but not in IE8:

    Here is the code in Javascript:

      //returns boolean not integer 
           function GetBestValue() 
            { 
               var combo = $find("<%= rcbTopBottom.ClientID %>"); 
               if (combo == nullreturn
                   return combo.get_value(); 
              
            } 
    In IE8 this code when actioned during the Page_Load (this method is called from another Javascript function using Page.ClientScript.RegisterClientScriptBlock in the Page_Load).

    FF returns the correct value but in IE8 this function returns always a null.  Its as if the ASP injection occurs too late in IE8.  I hope you can assist with this. (RadControls Q3 2009 SP1)

    Regards,

    Justin


  7. Dimo
    Admin
    Dimo avatar
    8332 posts

    Posted 11 Feb 2010 Link to this post

    Hi Justin,

    Scripts registered with Page.ClientScript.RegisterClientScriptBlock are executed before the ASP.NET AJAX library has been loaded and all client control instances have been initialized. You can use

    http://www.asp.net/ajax/documentation/live/mref/M_System_Web_UI_ScriptManager_RegisterStartupScript_5_0feb167c.aspx

    In this way, the script will be executed after the ASP.NET AJAX library has been loaded, but before the control instances have been created. So in the startup script you have to subscribe to the PageRequestManager pageLoaded client event:

    http://www.asp.net/AJAX/Documentation/Live/ClientReference/Sys.WebForms/PageRequestManagerClass/PageRequestManagerPageLoadedEvent.aspx

    Here is some more information:

    http://blogs.telerik.com/dimodimov/posts/08-12-13/don_t_use_body_onload_in_asp_net_ajax_websites.aspx


    Kind regards,
    Dimo
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  8. Lyle Groome
    Lyle Groome avatar
    22 posts
    Member since:
    Dec 2005

    Posted 12 Apr 2010 Link to this post

    My $find() was also always coming back as null, but my usage was only looking things up on click events not pageloads so it wasn't timing. Turns out that $find will bomb if you have a javascript syntax issue in your functions. In my case an extra "{" in one of my page's JS functions was at fault and after finding it and correcting it $find worked again for me.
  9. Justin
    Justin avatar
    4 posts
    Member since:
    Aug 2008

    Posted 13 Apr 2010 Link to this post

    Hi Dimo

    That worked brilliantly.  What I did was, I moved the Javascript method out of the Page.ClientScript.RegisterClientScriptBlock
    and placed the following in the actual page itself.

    <script type="text/javascript">
    Sys.Application.add_load(LoadGrid);
    </script>


    This sorts out the whole problem I have been having.

    Much appreciated and sorry for the late reply!

    Justin

  10. Ganesh
    Ganesh avatar
    3 posts
    Member since:
    Oct 2013

    Posted 09 Oct 2013 Link to this post

    Hi Dimo

    Even i m facing the same problem with $find("RadEditorID")
    in my case i have a asp repeater control and in that i have a Radeditor control

    and i have retrive the html text from all the RadEditor when the page is ready.

    so i have tried to use document.ready function of jquery
    the code is as follows

     $(document).ready(function () {
            $(".singleQuestion").find(".RadEditor").each(function () {
                    var x = $(this).attr("id"); //i m able to the the ID  properly
                    y = $find(x).get_html(true);
                    alert(y);
             });
     });

    the error i get is "'null' is null or not an object"
    it work fine with FireFox.

    can u please help me on this
  11. Vessy
    Admin
    Vessy avatar
    1385 posts

    Posted 11 Oct 2013 Link to this post

    Hello Ganesh,

    Could you try moving the desired functionality to the Application load handler, which will ensure that the controls in the page are loaded correctly and see if the problem still occurs?
    Sys.Application.add_load(function () {
        $(".singleQuestion").find(".RadEditor").each(function () {
            var x = $(this).attr("id"); //i m able to the the ID  properly
            y = $find(x).get_html(true);
            alert(y);
        });
    });

    Regards,
    Veselina Raykova
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  12. Ganesh
    Ganesh avatar
    3 posts
    Member since:
    Oct 2013

    Posted 14 Oct 2013 Link to this post

    Thanks a lot "Veselina Raykova"
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017