This is a migrated thread and some comments may be shown as answers.
Selecting TextBox text when residing in a RadWindow
4 Answers 26 Views
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 02 Feb 2012, 04:54 AM
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.

4 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 03 Feb 2012, 04:17 PM
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
0
Robert
Top achievements
Rank 1
answered on 03 Feb 2012, 05:19 PM
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
0
Accepted
Marin Bratanov
Telerik team
answered on 06 Feb 2012, 03:10 PM
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 >>
0
Robert
Top achievements
Rank 1
answered on 12 Feb 2012, 11:21 PM
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
Asked by
Robert
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Robert
Top achievements
Rank 1
Share this question
or