Updating Hidden Textbox with new text

4 posts, 0 answers
  1. Daniel
    Daniel avatar
    9 posts
    Member since:
    Nov 2013

    Posted 07 Apr 2014 Link to this post

    I am using Telerik controls V2014.1.225.45 and am a newbie.

    I am trying to update a TextBox that I have added as "hidden".  I am unsuccessful.  I've looked at most of the forums for help have not found how to correct this problem.

    The text in the hidden text box is set to "a".  I am able to retrieve this value.  However, all variations of the set_text or set_value fail to change the value. 

    Here is my Javascript code:

            <script type="text/javascript" id="Script1">
                //<![CDATA[

                function RadToolBar1_ButtonClicked(sender, args) {

                    alert(args.get_item().get_level());
                    if (args.get_item().get_level() == 1) {
                        alert(args.get_item().get_text());
                        var w = $find("<%= RadTextBox1.ClientID %>");
                        var wb = $get("<%= RadTextBox1.ClientID %>").value;
                        var wa = document.getElementById("<%= RadTextBox1.ClientID %>").style;
                        var x = $find("<%= RadPanelBar1.ClientID %>");
                        var x = document.getElementById("<%= RadPanelBar1.ClientID %>");
                        var y = document.getElementById("<%= RadPanelBar1.ClientID %>").style;
                        var y = document.getElementById("<%= RadPanelBar1.ClientID %>").style;
                        y.visibility = "hidden";
                        y.display = "none";
                        wa.display = "none";
                        wb.value = "hidden";
                        wb.set_value = "hidden";
                        w.set_textBoxValue = "hidden";
                        document.getElementById("<%= RadTextBox1.ClientID %>").set_textBoxValue = "hidden";
                        var v = document.getElementById("<%= RadTextBox1.ClientID %>").value;
                        alert(args.get_item().get_text());

                }

  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5361 posts

    Posted 07 Apr 2014 Link to this post

    Hello Daniel,

    You need to use the client-side API of the RadTextoBox object in order to modify its value: http://www.telerik.com/help/aspnet-ajax/input-client-side-radtextbox.html. Here is a small example:

    <div style="display:none;">
        <telerik:RadTextBox ID="RadTextBox1" runat="server">
        </telerik:RadTextBox>
    </div>
    <asp:Button ID="Button1" Text="get value" OnClientClick="getTbValue();
     
    return false;" runat="server" />
    <script type="text/javascript">
        function myfunction() {
            var w = $find("<%= RadTextBox1.ClientID %>");
            w.set_value("a new value");
         
            Sys.Application.remove_load(myfunction);
        }
        Sys.Application.add_load(myfunction);
        function getTbValue() {
            var w = $find("<%= RadTextBox1.ClientID %>");
            alert(w.get_value());
        }
    </script>

    Note how I use the Sys.Application.Load event to execute the script - this is the earliest event when you can be sure IScriptControls like ours are available on the client. It seems that you are using another control's event so it should be OK, I just wanted to provide this as an additional example.

    Regards,

    Marin Bratanov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Daniel
    Daniel avatar
    9 posts
    Member since:
    Nov 2013

    Posted 07 Apr 2014 in reply to Marin Bratanov Link to this post

    OK, being a newbie here, I am a bit confused.

    The end game for this exercise, is to send information into the C# program on the ClickEvent to indicate what the current value of the visibility setting for the Telerik Panel.

    I wanted to use a hidden text box to communicate this.

    The scenario is this:

    1.  Page is displayed with the Telerik Panel not visible.
    2.  User clicks on a Telerik Menu bar item.  There is an OnClientClicked event handler coded as a Javascript and a C# method called RadToolBar1_ButtonClick in the program.
    3.  So, I was hoping that the Javascript would be executed first (which seems to be the case).
    4.  This Javascript sets the Panel to visible, and I was hoping to set the hidden TextBox to indicate this.
    5.  Next the C# method gets executed and evaluates this hidden TextBox for the most current visibility state as set by the Javascript execution.

    Is there any coordination made between the OnClientClicked script and the "MyFunction" Javascript so that I can do this communication?
  4. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5361 posts

    Posted 09 Apr 2014 Link to this post

    Hello Daniel,

    I think it would be easier to use the standard asp:HiddenField control that renders as a simple <input type="hidden" /> instead of a RadTextBox. I am attaching here a simple page that shows the approach. I hope it helps.


    Regards,

    Marin Bratanov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top