+1-888-365-2779
Try Now
More in this section

RadTextBox

16 posts, 1 answered
  1. Andrew
    Andrew avatar
    202 posts
    Registered:
    05 Jun 2009
    12 Jul 2009
    Link to this post
    I am having problems with RadTextBox and JS.

    I am trying to change the text in a textbox using JS like this:

     

     

     

    function OnClientClose(oWnd, args) {  
     
    var arg = args.get_argument();  
     
    var textBox1 = document.getElementById('<%=TextBox1.ClientID%>');  
     
    textBox1.value = arg.Name;  
     
    }  
     
    }  
     


    But it only works with a normal textbox, and not with a RadTextBox. The change only apears in the RadTextBox when it gets focus. Very strange.

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 Jul 2009
    Link to this post
    Hi Andrew,

    I tried sample js code that executes OnLoad event and there is no problem with RadTextBox control. You can give a try to the code below:

    <script type="text/javascript"
     
       function myFunction(sender, args) { 
           var textBox = $find("<%= RadTextBox1.ClientID %>"); 
           textBox.set_textBoxValue("test-test"); 
       } 
        
        
    </script> 
     
    <telerik:RadTextBox ID="RadTextBox1" runat="server" TextMode="SingleLine"
    <ClientEvents OnLoad="myFunction" /> 
    </telerik:RadTextBox> 


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Andrew
    Andrew avatar
    202 posts
    Registered:
    05 Jun 2009
    13 Jul 2009
    Link to this post
    You code, does work. I am however doing something slightly different.

    Here is my JS code:

    <script type="text/javascript"
        function OnClientClose(oWnd, args) { 
            //get the transferred arguments 
            var arg = args.get_argument(); 
            if (arg) { 
                var div = document.getElementById('<%=uxCategoryText.ClientID%>'); 
                div.value = arg.Name; 
     
                var hField = document.getElementById('<%=hCategory.ClientID%>'); 
                hField.value = arg.ID; 
            } 
        } 
    </script> 

    Here is my html code:

    <li> 
                                <asp:Label ID="lblCategories" runat="server" Text="Label">Categories</asp:Label> 
                                <telerik:RadTextBox ID="uxCategoryText" runat="server" EmptyMessage="Select Category" 
                                    ReadOnly="True"
                                </telerik:RadTextBox> 
                                <button id="uxCategory"
                                    Select</button> 
                                <asp:HiddenField ID="hCategory" runat="server" /> 
                                <telerik:RadWindowManager ID="RadWindowManager1" Behaviors="Close" runat="server" 
                                    Overlay="True"
                                    <Windows> 
                                        <telerik:RadWindow OpenerElementID="uxCategory" Title="Select Category" ID="RadWindow1" 
                                            NavigateUrl="../Popups/Categories.aspx" OnClientClose="OnClientClose" runat="server"
                                        </telerik:RadWindow> 
                                    </Windows> 
                                </telerik:RadWindowManager> 
                            </li> 


    As you can see, i have a text box (RadTextBox) a button and a RadWindow. When the button is clicked a window pops up. (using the radwindow manager) then i select an item and close the window. The radWindow has an 'OnClientClose' event, at which point it runs the JS function. The function searches and populates the TextBox.
    If the textBox is a normal TextBox, it works fine. If the TextBox is a RadtextBox, it does not appear to work, until you click or give focus to the TextBox. At which point, the text does appear.

    I need to use the radTextBox, because i use those textboxes all over the page, and need both functionality as well as consistency in style.


  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    14 Jul 2009
    Link to this post
    Hi Andrew,

    The problem is in the js you are using. Below is a sample code that I use to return the tile of the selected text. For testing purposes I used on of the build in dialogs in Sitefinity(ItemDialog).

    <script type="text/javascript">  
        function OnClientClose(oWnd, args) {  
            //get the transferred arguments  
            var arg = args.get_argument(); 
            if (arg) { 
                // get the RadTextBox control 
                var radTextBox = $find("<%= RadTextBox1.ClientID %>"); 
                // get the args.title 
                radTextBox.set_textBoxValue(arg.title); 
                // add the other logic here 
            } 
        } 
    </script> 
     
    <li>  
        <asp:Label ID="lblCategories" runat="server" Text="Label">Categories</asp:Label>  
        <telerik:RadTextBox ID="RadTextBox1" runat="server" EmptyMessage="Select Category"  
            ReadOnly="true">  
        </telerik:RadTextBox>  
        <button id="uxCategory">  
            Select</button>  
        <asp:HiddenField ID="hCategory" runat="server" />  
        <telerik:RadWindowManager ID="RadWindowManager1" Behaviors="Close" runat="server"  
            Overlay="True">  
            <Windows>  
                <telerik:RadWindow OpenerElementID="uxCategory" Title="Select Category" ID="RadWindow1" 
                    NavigateUrl="~/Sitefinity/UserControls/Dialogs/ItemDialog.aspx" OnClientClose="OnClientClose" runat="server">  
                </telerik:RadWindow>  
            </Windows>  
        </telerik:RadWindowManager>  
     </li>  

    You can gather more information about input controls client side api from here.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
    Answered
  5. Andrew
    Andrew avatar
    202 posts
    Registered:
    05 Jun 2009
    15 Jul 2009
    Link to this post
    I am afraid it does not work for me.
    I changed my code to reflect yours and i get an JS error.
    "Function expected".
    When i change $find back to document.getElementById i don't get the error, but still no change.
    Also unlike when i used .value using "set_textBoxValue" does not even apear when i click the text box.

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    15 Jul 2009
    Link to this post
    Hi Andrew,

    I am sorry, I am not able to reproduce the error locally using the code I sent you. I am sending you a sample video that illustrates setting the title of an content item as RadTextBox text. You can debug the js to see what exactly throws the error at your end.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Andrew
    Andrew avatar
    202 posts
    Registered:
    05 Jun 2009
    15 Jul 2009
    Link to this post
    That is strange.
    Is it perhaps related to my popup window?
    Can i send you my code so you can have a look at what i am doing wrong?
  8. Andrew
    Andrew avatar
    202 posts
    Registered:
    05 Jun 2009
    15 Jul 2009
    Link to this post
    Hi Ivan,

    I posted my code in asupport ticket. (227446)

    Could you please have a look and let me know what it is that i am doing wrong. How is the code different from yours?

    Thanks
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    15 Jul 2009
    Link to this post
    Hi Andrew,

    Send all the code you are using and I will look into the matter.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  10. Andrew
    Andrew avatar
    202 posts
    Registered:
    05 Jun 2009
    15 Jul 2009
    Link to this post
    Thanks for your help Ivan.
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    15 Jul 2009
    Link to this post
    Hi Andrew,

    Let me know if you get stuck somewhere.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  12. Marirena Xagorari
    Marirena Xagorari avatar
    4 posts
    Registered:
    05 Nov 2009
    05 Nov 2009
    Link to this post
    Dear Andrew,

    I have the exact same problem, with a popup window that I close I try to change the value of a radtextbox, but only onfocus I see the value.

    Did you find an answer in your issue?

    Thanks in advance
  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    05 Nov 2009
    Link to this post
    Hello Marirena Xagorari,

    The problem was is some properties that Andrew was not set correctly. Are you able to reproduce the problem with the code provided in the post marker as answer?

    Best wishes,
    Ivan Dimitrov
    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.
  14. Marirena Xagorari
    Marirena Xagorari avatar
    4 posts
    Registered:
    05 Nov 2009
    05 Nov 2009
    Link to this post
    Thank you Ivan. I have not seen that there was a post marked as  "answer", with a little change it worked.

    Thanks again!
  15. Marirena Xagorari
    Marirena Xagorari avatar
    4 posts
    Registered:
    05 Nov 2009
    09 Nov 2009
    Link to this post
    Dear Ivan,

    I have another issue now. RadTextbox gets correctly the value on closing the window, but on focus it looses the value, it returns in the previous value that I had in the Textbox. Can you give me an idea?

    Thanks in advance
    Marirena Xagorari
  16. Marirena Xagorari
    Marirena Xagorari avatar
    4 posts
    Registered:
    05 Nov 2009
    18 Nov 2009
    Link to this post
    For anyone that he has interest in this issue. I replace the radTextBox.set_textBoxValue(arg.title);  with radTextBox.set_value(arg.title);  and it worked just fine!

    Thanks
Register for webinar
16 posts, 1 answered