Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Window > Selecting TextBox text when residing in a RadWindow

Answered Selecting TextBox text when residing in a RadWindow

Feed from this thread
  • Robert Intermediate avatar

    Posted on Feb 1, 2012 (permalink)

    For a long time now I've used a dependable Javascript function to preselect the text in a textbox.  However I discovered today that when a textbox resides in an AJAXifield RadWindow, a more complex approach has to be used.  Here's the code showing both approaches:

      function SetFocusAndSelectText(tbID) {<br>    var textBox = $get(tbID);<br><br>    // Standard approach<br>    textBox.focus();<br>    textBox.select();<br><br><br>    // Approach when the TextBox resides in an AJAXified RadWindow<br>    //    function f() {<br>    //      debugger <br>    //      if (textBox != null) {<br>    //        textBox.focus();<br>    //        textBox.select();<br>    //      }<br><br>    //      Sys.Application.remove_load(f);<br>    //    }<br><br>    //    Sys.Application.add_load(f);<br>  }

    I'm wondering if there's a way to test for whether the textbox sits within a RadWindow?  If so, then I could just call one function and let it decide which approach to use.

    Sincerely,

    Robert W.

    Reply

  • Marin Bratanov Marin Bratanov admin's avatar

    Posted on Feb 3, 2012 (permalink)

    Hi Robert,

    I assume your textbox is in the ContentTemplate of a RadWindow. If this is the case then it acts like any other container - you can check, for example for its parent elements, yet this is an unsafe approach for a common function - you cannot be always certain what the page's layout would be.

    The approach when you use the Sys.Application.Load event to make sure the response is received would also be applicable for a regular postback, so you can leave only this function.

    Alternatively, you can create two functions - one to use with AJAX and one - with your current approach for the rest of the scenarios.


    Greetings,
    Marin
    the Telerik team
    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 their blog feed now

    Reply

  • Robert Intermediate avatar

    Posted on Feb 3, 2012 (permalink)

    Marin,

    You wrote: "The approach when you use the Sys.Application.Load event to make sure the response is received would also be applicable for a regular postback, so you can leave only this function."

    I would have thought that too but I tested the Sys.Application only version on a page where the controls were not in a RadWindow.  It didn't work.

    Robert

    Reply

  • Answer Marin Bratanov Marin Bratanov admin's avatar

    Posted on Feb 6, 2012 (permalink)

    Hello Robert,

    I tested this approach and things seem to be working properly with me: http://screencast.com/t/W2H8iZvrdRS. I only moved the line where we get the reference inside the function we call f, so that I am sure that it can be referenced. I am also attaching my test page as a reference. Please compare it with your scenario and try to find the differences. What I would advise is that  you make sure you pass a correct ClientID to this JS function so that you get a correct reference.


    Regards,
    Marin
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
    Attached files

    Reply

  • Robert Intermediate avatar

    Posted on Feb 12, 2012 (permalink)

    Marin,

    My apologies for the delay in getting back to you.

    In any case, your solution works perfectly in both RadWindow and non-RadWindow containers.  I'm really not sure why the approach didn't seem to be working for me before. But all is good now!

    Robert

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Window > Selecting TextBox text when residing in a RadWindow
Related resources for "Selecting TextBox text when residing in a RadWindow"

ASP.NET Window Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  |  Step-by-step Tutorial  ]